1 / 17

Integrating RPG and Java Server Pages

Welcome. Gulf Coast Midrange Users Group. Topic. Integrating RPG and Java Server Pages. 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.

Télécharger la présentation

Integrating RPG and Java Server Pages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome Gulf Coast Midrange Users Group Topic Integrating RPG and Java Server Pages

  2. 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

  3. 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.

  4. Java Server Pages Requirements • Java Server Pages require the • Tomcat Jsp Container.

  5. 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> <% } %> Jsp to use java class LoginMain And refer to program as “LI” If rtnCd equals “1” forward user to Welcome page Else Redisplay Login Page

  6. 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 Login does not contan any code and has the “native” modifier While getUserId and getPassword contain code and are not “native”

  7. 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.

  8. Calling AS/400 Java Native Method Requirements /** * Find Login Service Program */ static { System.loadLibrary("SRVLOGIN"); } /** * Login native method */ public native String Login(); Find Service Program “SRVLOGIN” in library list Call to “native” method “Login”

  9. 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 A B Java calls Native Method Login Found in Service Program Srvlogin C Login Returns string Object rtnCd back to Java program then to JSP

  10. 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 the Java method proto-typed C B A

  11. Visual Representation of Interaction A B <%rtnCd = LI.Login();%> Jsp makes call to Java program method Java Method is a native method. Calls RPG Sub-Procedure D C RPG Sub-Procedure performs all business logic. Accesses database and returns status code to java program and JSP <%if ((rtnCd.equals("1"))) { %> <jsp:forward page="Welcome.html"></jsp:forward> <% Jsp reacts to rtncd from RPG

  12. 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 NOTE Custom Tag Libs can improve development time often eliminating coding Two Main JSP Development FrameWorks: Struts Java Server Faces

  13. 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 >

  14. Java Server Faces and RPG Interaction <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

  15. Java Server Faces Navigation 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>

  16. 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.

  17. Thank You and support your GCMUG

More Related