1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    Pass WML variables to Servlet

    Hi Guys!

    I have the following problem. I am using a servelt to write 2 cards (card login and card valid). I need to pass a variable from card login to card valid. But before I can pass the value in the variables to card valid, I need to pre-process them using Java. I tried posting the variables but this does not work. I always receive the values as "null" in the valid card. Could someone pls help me with this problem. Below is the Servlet code:

    package com.omh.wap;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class Convert extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    // Set the content type of the response

    // Create a PrintWriter to write the response
    PrintWriter out = new PrintWriter(resp.getOutputStream());

    // Login Card
    out.println("<?xml version=\"1.0\"?>");
    out.println("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"");
    out.println(" \"http://www.wapforum.org/DTD/wml_1.1.xml\">");
    out.println(" <card id=\"login\" title=\"Login\">");
    out.println(" <p align=\"left\">");
    out.println(" <fieldset>(1) Please enter <b>username</b>:</fieldset>");
    out.println(" <input name=\"Name\" format=\"7A\" type=\"text\"/>");
    out.println(" <fieldset>(2) Please enter <b>password</b>:</fieldset>");
    out.println(" <input name=\"Pass\" format=\"5N\" type=\"password\"/>");

    out.println("<do type=\"accept\" name=\"next\" label=\"Go\">");
    out.println("<go href=\"#valid" method=\"post\">"); // Go to Valid Card
    out.println("<postfield name=\"userName\" value=\"$(Name)\"/>");
    out.println("<postfield name=\"userPass\" value=\"$(Pass)\"/>");

    // Could these 2 lines be the source of the problem?
    String Name = req.getParameter("userName");
    String Pass = req.getParameter("userPass");

    // Validate Card
    out.println(" <card id=\"valid\" title=\"Validation\">");
    out.println(" <p align=\"left\">");

    if (Name.equals("USER") && Pass.equals("12345")) {
    out.println("Welcome <b>" + Name + "</b>! Username and Password have been verified. Please proceed.");
    out.println(" <do type=\"accept\" name=\"next\" label=\"Proceed\">");
    out.println(" <go href=\"http://localhost:8080/jsdg-wap/LOF3\" method=\"post\">");
    out.println(" </go>");
    out.println(" </do>");

    else {
    out.println("Invalid Username and/or Password entered. Please try again.");
    out.println(" <do type=\"options\" name=\"back\" label=\"Back\">");
    out.println(" <go href=\"#login" method=\"post\">");
    out.println(" </go>");
    out.println(" </do>");

    out.println(" </p>");
    out.println(" </card>");


    public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    doGet(req, resp);



    Thanks a Lot!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Beverly Hills
    Rep Power

    I see the problem

    The variables are never getting to the servlet because they are never being sent to the servlet. Remember, a WML "page" is not a page at all. WML is totally different from HTML (and much better for mobile devices I might add). WML stacks consist of cards. Once the phone loads an entire stack (ie, .wml file) then it doesn't need to go back to the server ever to switch between cards within that stack (.wml file). So, when your card does a <go> to id #valid, it just goes to it in memory, without making any request to the server, even though you are using method=post. It would take me some time to read through the spec of wml and figure out if this is really the correct behavior, but in practice, I am not surprised that real devices would do it this way, and it may be the spec, also.

    So the solution is to break these two cards into separate .wml files.

    Let me know how it goes.

    Take the pain out of creating a WML server

IMN logo majestic logo threadwatch logo seochat tools logo