× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Login/Logoff for AS/400 Servlet
  • From: Geert Van Landeghem <gvl@xxxxxxxxxxxxxx>
  • Date: Thu, 4 May 2000 09:24:32 +0100

The best you can do is to create an .html page were people can enter
their id and password with a submit button which activates a servlet.
This servlet uses the toolbox to validate the user & password:
- the information comes from an as400 object (file, userspace, index,...) or
- the validation is done with an as400 *usrprf using the validate() method,
  which came along with modification 3 of the toolbox and allows you to
create 
  your own login-screen if you want to (you don't need an initial connection
  to verify the user and password)
There are several ways to get this information along to other servlets
after login authorization. (hidden information, sessions, cookies,...)

As an example I've included a piece of code that we actually used for
a login screen:
-We use a database file to store the header and footer 
 lines of each generated .html file on the AS/400. Multiple 
 languages are supported in this way 
 (depending on the userid the customer gets a personalized website:
  "Welcome Mr. xxxx to our website")
-Between header and footer lines we normally display a table with
information
 (items & price & picture ...) This table is constructed by calling
 a 'driver' program on the AS/400 which returns data that is parsed into
 the returned .html page 

Enjoy servlet programming!

import com.ibm.as400.access.*;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

/*
 * AS400LoginServlet.
 */

public class AS400LoginServlet extends HttpServlet {
  private AS400 as400=null;
  private ProgramCall pgm=null;
  ProgramParameter[] plist=new ProgramParameter[2];

  public void init(ServletConfig config) {
    Print.printStatus("Servlet AS400Login : init() method start");
    try {   
      super.init(config);
    } 
    catch(Exception e) {
      Print.printError("init()","calling super.init(config)",e);
    }
    try {
      as400 = Util.getAS400(this);
      pgm = Util.getDriverProgram(this,as400); 
      plist = pgm.getParameterList();
    }
    catch(Exception e) { 
      Print.printError("init()","creating connection and programCall",e);
    }
    Print.printStatus("Servlet AS400Login : init() method end");
  } 
   
  public void doPost (HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
  {
    String in=null;
    String userId=null;
    String passWord=null;
    String layOut=null;
    res.setContentType("text/html");
    ServletOutputStream out = res.getOutputStream();
    // GET INITIAL PARAMETERS
----------------------------------------------------------------
    userId=req.getParameter("User");
    passWord=req.getParameter("Password");
    // GET INITIAL PARAMETERS
----------------------------------------------------------------        
    if (userId==null) {
      userId="X";
    }
    else {
      userId=userId.toUpperCase();
    }
    if (passWord==null){ 
      passWord="X";
    }
    else {
      passWord=passWord.toUpperCase();
    }
    Print.printStatus("Userid=" + userId);
    Print.printStatus("Password=" + passWord);
    // CALLING DRIVER FOR LAYOUT
BEGIN-------------------------------------------------------
    AS400Text nametext = new AS400Text(128);
    plist[0] = new ProgramParameter( nametext.toBytes("#RQC=001;#USR=" +
userId.trim() 
                 + ";#PSW=" +passWord));
    Print.printStatus("In=" + "#RQC=001;#USR=" + userId  
                 + ";#PSW=" +passWord);
    try {
      if (pgm != null) { 
        if (pgm.run()) {
          AS400Text text=new AS400Text(Util.PARAMETERSIZE);
          layOut = (text.toObject(plist[1].getOutputData())).toString();   
          Print.printStatus("layOut="+layOut);
        }
        else {
          AS400Message[] messagelist = pgm.getMessageList();
          for (int i=0; i < messagelist.length; i++){// show each message
            Print.printStatus( messagelist[i].toString() );
          }
        }
      } 
    }
    catch(Exception e) { 
        Print.printError("doPost"," calling driver program",e);
    }   

    // CALLING DRIVER FOR LAYOUT
END----------------------------------------------------------

    // CHECKING ACCESS
BEGIN------------------------------------------------------------------ 
    Print.printStatus("#ACC=" + Util.getCode(layOut,"#ACC=")); 
    if (Util.getCode(layOut,"#ACC=").equals("1")) {

    // CHECKING ACCESS
IF--------------------------------------------------------------------- 
      try {
        // HEADER
BEGIN-----------------------------------------------------------------------

        // print header 
        Html.printHeader(out, layOut);
        // print header lines
        Html.printHeaderLines(out, layOut);       
        // HEADER
END-------------------------------------------------------------------------


        // BODY
BEGIN-----------------------------------------------------------------------
--    
        // CALLING DRIVER FOR ELEMENTS BEGIN
LOOP---------------------------------------------
          // BODY GENERATING HTML
BEGIN-------------------------------------------------------- 
          // BODY GENERATING HTML
END--------------------------------------------------------- 
          // GETTING RETURN AND LOW VALUE
CODES-----------------------------------------------
        // CALLING DRIVER FOR ELEMENTS END
LOOP-----------------------------------------------
        // BODY
END-------------------------------------------------------------------------
--
        // FOOTER
BEGIN-----------------------------------------------------------------------

        // print footer lines
        Html.printFooterLines(out,layOut);
        // print footer
        Html.printFooter(out); 
        // FOOTER
END-------------------------------------------------------------------------

      }
      catch(Exception e) {
      }
    }
    // CHECKING ACCESS
ELSE------------------------------------------------------------------- 
    else {
      try {
        out.println("No access...try again");
    // CHECKING ACCESS
ENDIF------------------------------------------------------------------ 
    Print.printStatus("Servlet AS400Login : doPost() method end");
  }
     
  public String getServletInfo() {
    return "AS/400 Login Servlet";
  }
}


-----Original Message-----
From: Martinus Ivan [mailto:IVANM@MULTIPOLAR.CO.ID]
Sent: woensdag 3 mei 2000 11:36
To: 'JAVA400-L@midrange.com'
Subject: Login/Logoff for AS/400 Servlet


Hi All,
I create a servlet that add record to  AS/400 file from Browser and it
working great (using toolbox and RecordLevel Access). Now I try to add a
Logoff/Login function, once the logoff button pressed, the next request to
write to AS/400 is supposed to pop-up a login box again. Here is what I got
:

OBSERVATION :
The login pop-up only appear once for the first request after  I start the
servlet engine (JWSDK 1.0.1 on PC). But for next request or if I close and
re-open the Browser it won't pop-up the login box again. I'm pretty sure I
disconnectAllService() on my servlet (and watch no suspicios job hang on
wrkactjob) 
The only way to make it show up again is to stop and re-start the servlet
engine.

QUERY :
Could someone share the experience on how to create a logoff and login
Process, what technique should I use ? 
I'm expecting the login box can appear many times for one servlet instance.

Thank you in advance for your help.

regards,
Ivan. L





+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.