Integrating RPG and Java Server Pages
-
Upload
calvin-snider -
Category
Documents
-
view
20 -
download
3
description
Transcript of Integrating RPG and Java Server Pages
Integrating RPG and Java Server Pages
Gulf Coast Midrange Users GroupWelcome
Topic
Gulf Coast Midrange Users Group
Problem: Web Development for AS/400-RPG shops unaccustomed to Java or other web development languages.
Welcome to: Integrating RPG and Java Server Pages
Java Server Pages Definition
JavaServer Pages. A server-side technology, JavaServer pages are an extension to the Java servlet technology that was developed by Sun. JSPs have dynamic scripting capability that works in tandem with HTML code, separating the page logic from the static elements -- the actual design and display of the page. Embedded in the HTML page, the Java source code and its extensions help make the HTML more functional, being used in dynamic database queries, for example. JSPs are not restricted to any specific platform or server.
Java Server Pages Requirements
● Java Server Pages require the
● Tomcat Jsp Container.
Jsp Example
<jsp:useBean id="LI" class="meatOrder.LoginMain" scope="request"> <%rtnCd = LI.Login();%><%if ((rtnCd.equals("1"))) { %> <jsp:forward page="Welcome.html"></jsp:forward> <% <% } else { %> <HTML> <HEAD> <TITLE>Login.jsp</TITLE> </HEAD> <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> <% } %>
If rtnCd equals “1” forward user to Welcome pageElseRedisplay Login Page
Jsp to use java class LoginMain And refer to program as “LI”
Java Objects (Classes, Methods, Variables)
public class LoginMain {
* Program Variables */
public String userId = " ";public String passWord = " ";public String rtnCd = "0";
/** * Login native method */
public native String Login();
/** * Getter methods generated by Websphere */
/** Return User Id */public byte [] getUserId() {
return userId.getBytes();}
/** Return PassWord*/public byte [] getPassWord() {
return passWord.getBytes();}
Java program example contains:
1 java class (LoginMain)
3 variables(userId, passWord, rtnCd)
3 methods(Login, getUserId, getPassWord)
Note that method Logindoes not contan any codeand has the “native” modifier
While getUserId and getPasswordcontain code and are not “native”
The Java Native Interface
The Java Native Interface (JNI)
The JNI allows Java code that runs within a Java Virtual Machine (JVM) to operate with applications and libraries written in other languages, such as C, C++,Visual Basic and RPG ILE. In addition, the Invocation API allows you to embed the Java Virtual Machine into your native applications.
AS/400 Native RPGILE methods must be coded within Sub-Procedure Modules and made into Service Programs. The Service Program must reside within the library list.
Calling AS/400 Java Native Method Requirements
/** * Find Login Service Program */
static {System.loadLibrary("SRVLOGIN");
}
/** * Login native method */
public native String Login();
Call to “native” method “Login”
Find Service Program “SRVLOGIN” in library list
Jsp calling native RPG method/sub-procedure
<jsp:useBean id="LI" class="meatOrder.LoginMain" scope="request"> <%rtnCd = LI.Login();%>
<%if ((rtnCd.equals("1"))) { %> <jsp:forward page="Welcome.html"></jsp:forward>
/** * Login native method */
public native String Login();
3500 * Prototyped Native Java Method Login 3700 DLogin PR O Class(*JAVA:StringClass) 3800 D ExtProc(*JAVA 3900 D :LM 4000 D :LI) 4100 PLogin B Export 4200 DLogin PI O Class(*JAVA:StringClass)
JSP calls Java method Login
Java calls Native Method LoginFound in Service Program Srvlogin
Login Returns string ObjectrtnCd back to Java programthen to JSP
A
B
C
RPG and JNI ProtoTyping of “getter” method
/** Return User Id */
public byte [] getUserId() {return userId.getBytes();
} DGUI C 'getUserId' DLM C 'meatOrder.LoginMain' DLI C 'Login' * * Prototyped Java getUserId Method * B DgetUserId PR 10A D ExtProc(*JAVA D :LM D :GUI) DuserId S Like(GetUserId) C Eval UserId = getUserId(%This)
When the getUserId method is called in RPG it uses theJava method proto-typed
B
C
A
Java Method is a native method. Calls RPG Sub-Procedure
RPG Sub-Procedureperforms all businesslogic. Accesses databaseand returns status codeto java program and JSP
<%rtnCd = LI.Login();%>
Jsp makes call to Java program method
Visual Representation of Interaction
A B
CD
<%if ((rtnCd.equals("1"))) { %><jsp:forward page="Welcome.html"></jsp:forward><%
Jsp reacts to rtncd from RPG
JSP and RPG Integration Review
Java Native Interface (JNI) provides method of interfacing JSP's and RPG
RPG can access JSP forms thru prototyped “getter/setter” methods
Custom Tag Libs can improve development time often eliminating coding
NOTE
Two Main JSP Development FrameWorks:
Struts Java Server Faces
Java Server Faces Example
login.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <f:loadBundle basename="bundle.Messages" var="Message" /> <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 >
<h:commandButton id="submit" action="#{LoginMain.Login}" value="#{Message.login_button}" />
/** * Login native method */
public native String Login();
3500 * Prototyped Native Java Method Login 3700 DLogin PR O Class(*JAVA:StringClass) 3800 D ExtProc(*JAVA 3900 D :LM 4000 D :LI) 4100 PLogin B Export 4200 DLogin PI O Class(*JAVA:StringClass)
JSF calls Java Method
Java method is a “native” method
Calls RPG Sub-Procedure
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>
Java Server Faces Navigation
Conclusion
The integration of JSP and RPG can provide AS/400 developers unaccustomed to java development an inroad to more rapid web development.
RPG using JSP integration can “get/set” variables normally only reserved for java objects from the Apache HTTP/Tomcat JSP server.
Thank You and support your GCMUG