JSP.ppt - PowerPoint Presentatio by liwenting


Gulf Coast Midrange Users Group
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
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">
                                                                      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
<HEAD>                                             Else
</HEAD>                                            Redisplay Login Page
<H2 align="center">Autry Greer and Son's, Inc.</H2>
<FORM method="post" name="LogIn"
<p align="center">User Id : <INPUT type="text" name="userId" size="10"></p>
<p align="center">Password: <INPUT type="password" name="passWord"
<p align="center"><INPUT type="submit" name="logIn" value="Submit"></p>
<INPUT type="hidden" name="rtncd" value=null></FORM>
   Java Objects (Classes, Methods,
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() {
                      return passWord.getBytes();
                                                             While getUserId and getPassword
           }                                                 contain 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

      * Find Login Service Program
      */                                 Find Service Program
                                         “SRVLOGIN” in library list
      static {

      /**                             Call to “native” method “Login”
       * Login native method

      public native String Login();
Jsp calling native RPG method/sub-
 <jsp:useBean id="LI" class="meatOrder.LoginMain" scope="request">

<%rtnCd = LI.Login();%>                           JSP calls Java method Login            A
<%if ((rtnCd.equals("1"))) { %>
<jsp:forward page="Welcome.html"></jsp:forward>
           * Login native method
           */                                             Java calls Native Method Login
         public native String Login();                    Found in Service Program Srvlogin
 3500     * Prototyped Native Java Method Login
 3700     DLogin        PR          O Class(*JAVA:StringClass)
 3800     D                           ExtProc(*JAVA
 3900     D                              :LM
 4000     D                              :LI)                        Login Returns string Object
 4100     PLogin        B             Export
 4200     DLogin        PI         O Class(*JAVA:StringClass)        rtnCd back to Java program
                                                                     then to JSP
   RPG and JNI ProtoTyping of
        “getter” method
/** Return User Id   */                     When the getUserId method
                                            is called in RPG it uses the
             public byte [] getUserId() {   Java method proto-typed
  C             return userId.getBytes();

      DGUI                C            'getUserId'
      DLM                 C
      DLI                 C            'Login'
 B    *     Prototyped Java getUserId Method
B     DgetUserId          PR               10A
D                                   ExtProc(*JAVA
D                                 :LM
A                                :GUI)
    DuserId        S          Like(GetUserId)
             Visual Representation of Interaction
             A                              B

<%rtnCd = LI.Login();%>             Java Method is a native
                                    method. Calls RPG
 Jsp makes call to                  Sub-Procedure
 Java program
                  D                                C

                                    RPG Sub-Procedure
<%if ((rtnCd.equals("1"))) { %>
                                    performs all business
                                    logic. Accesses database
                                    and returns status code
Jsp reacts to rtncd                 to java program and JSP
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”
 Custom Tag Libs can improve development time often
 eliminating coding
    Two Main JSP Development FrameWorks:

   Struts                Java Server Faces
                       Java Server Faces Example


<%@   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" />

        <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: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:message for="password" /><br />
              <h:commandButton id="submit" action="#{LoginMain.login}" value="#{Message.login_button}"
</ body >
</ html >
           Java Server Faces and RPG Interaction

<h:commandButton id="submit" action="#{LoginMain.Login}"
value="#{Message.login_button}" />                JSF calls Java
          * Login native method

        public native String Login();
                                                                Java method is a “native”
3500     * Prototyped Native Java Method Login
3700     DLogin        PR          O Class(*JAVA:StringClass)
                                                                Calls RPG Sub-Procedure
3800     D                           ExtProc(*JAVA
3900     D                              :LM
4000     D                              :LI)
4100     PLogin        B             Export
4200     DLogin        PI         O Class(*JAVA:StringClass)
     Java Server Faces Navigation



The integration of JSP and RPG can provide AS/400 developers
unaccustomed to java development an inroad to more rapid web

RPG using JSP integration can “get/set” variables normally only
reserved for java objects from the Apache HTTP/Tomcat JSP
       Thank You
and support your GCMUG

To top