Professional Documents
Culture Documents
●
Java Server Pages require the
●
Tomcat Jsp Container.
Jsp Example
<jsp:useBean id="LI" class="meatOrder.LoginMain" scope="request">
Jsp to use java class LoginMain
<%rtnCd = LI.Login();%>
<%if ((rtnCd.equals("1"))) { %>
And refer to program as “LI”
<jsp:forward page="Welcome.html"></jsp:forward>
<%
<%
} else {
If rtnCd equals “1” forward
%> user to Welcome page
<HTML>
<HEAD> Else
<TITLE>Login.jsp</TITLE>
</HEAD>
Redisplay Login Page
<BODY>
<H2 align="center">Autry Greer and Son's, Inc.</H2>
<FORM method="post" name="LogIn"
action="http://S1041402/app1/jsp/Login.jsp">
<p align="center">User Id : <INPUT type="text" name="userId" size="10"></p>
<p align="center">Password: <INPUT type="password" name="passWord"
size="10"></p>
<p align="center"><INPUT type="submit" name="logIn" value="Submit"></p>
<INPUT type="hidden" name="rtncd" value=null></FORM>
</BODY>
</HTML>
<%
}
%>
Java Objects (Classes, Methods,
Variables)
public class LoginMain {
Java program example contains:
* Program Variables
*/
1 java class (LoginMain)
public String userId = " ";
public String passWord = " ";
/**
public String rtnCd = "0";
3 variables(userId, passWord, rtnCd)
* Login native method
*/
3 methods(Login, getUserId, getPassWord)
public native String Login();
/**
* Getter methods generated by Websphere
Note that method Login
*/ does not contan any code
/** Return User Id */ and has the “native”
public byte [] getUserId() {
return userId.getBytes(); modifier
}
/** Return PassWord */
public byte [] getPassWord() { While getUserId and getPassword
return passWord.getBytes();
} contain code and are not “native”
The Java Native Interface
/**
* Find Login Service Program
*/ Find Service Program
“SRVLOGIN” in library list
static {
System.loadLibrary("SRVLOGIN");
}
<%rtnCd = LI.Login();%>
JSP calls Java method Login A
<%if ((rtnCd.equals("1"))) { %>
<jsp:forward page="Welcome.html"></jsp:forward> B
/**
* Login native method
*/
Java calls Native Method Login
public native String Login();
Found in Service Program Srvlogin
DGUI C 'getUserId'
DLM C
'meatOrder.LoginMain'
B
DLI C 'Login'
*
* Prototyped Java getUserId Method
A *
B DgetUserId PR
Visual Representation of Interaction
A B
RPG Sub-Procedure
<%if ((rtnCd.equals("1"))) { %>
<jsp:forward
performs all business
page="Welcome.html"></jsp:forward
> logic. Accesses database
<%
and returns status code
Jsp reacts to rtncd to java program and JSP
from RPG
JSP and RPG Integration Review
login.jsp
<html>
<head><title>Login</title></head>
<body>
<f:view>
<h:form id="loginForm" >
*<h:message for="loginForm" /><br />
<h:outputText value="#{Message.username_label}" />
<h:inputText id="username" value="#{LoginMain.userName}" required="true" >
<f:validateLength maximum="15" minimum="3" />
</h:inputText>
<h:message for="username" /><br />
<h:outputText value="#{Message.password_label}" />
<h:inputSecret id="password" value="#{LoginMain.passWord}" required="true" >
<f:validateLength maximum="15" minimum="3" />
</h:inputSecret>
<h:message for="password" /><br />
<h:commandButton id="submit" action="#{LoginMain.login}" value="#{Message.login_button}"
/>
</h:form>
</f:view>
</ body >
</ html >
Java Server Faces and RPG Interaction
faces-config.xml
<navigation-rule>
<from-view-id>/Login.jsp</from-view-id>
<navigation-case>
<from-outcome>1</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>0</from-outcome>
<to-view-id>/Login.jsp</to-view-id>
</navigation-case>
</navigation-rule>