JSP.ppt - PowerPoint Presentatio by liwenting

VIEWS: 52 PAGES: 17

									           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
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
<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() {
                      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
          Requirements

/**
      * Find Login Service Program
      */                                 Find Service Program
                                         “SRVLOGIN” in library list
      static {
      System.loadLibrary("SRVLOGIN");
                  }

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

      public native String Login();
Jsp calling native RPG method/sub-
             procedure
 <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>
                                                                 B
        /**
           * 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
                                                                         C
 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
'meatOrder.LoginMain'
      DLI                 C            'Login'
      *
 B    *     Prototyped Java getUserId Method
      *
B     DgetUserId          PR               10A
D                                   ExtProc(*JAVA
D                                 :LM
D
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
 method
                  D                                C

                                    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


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



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

        public native String Login();
                                                                Java method is a “native”
                                                                        method
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

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

								
To top