I'm trying to implement a "self-validating" JSP form on Tomcat 3.1
(Win98/Netscape 4.7) which can be used to gather details (user name) which
are then forwarded to a servlet. The servlet forwards the posted data back
to the original JSP page for review.

When I run the JSP page, the default name is displayed, and I change the
name from "default" to "Bob". When the form is submitted to the servlet, it
reports that the name is still "default". How can I get the servlet to
recognise the newly posted data and report the name correctly as "Bob"? I
expected that the JSP page would push the "test" bean into the session and
that the servlet would access the same bean during the post - but this
doesn't appear to happen.

The outline code is below :


### test.jsp

...

<jsp:useBean id="test" class="freesia.Test" scope="session">
  <jsp:setProperty name="test" property="*" />
</jsp:useBean>

<form action="/freesia/servlet/test_servlet" method="post">

Enter a name : <input type="text" name="name" value="<jsp:getProperty
name="test" property="name" />"

<input type="submit" value="submit">
</form>
...


### test_servlet 

  public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

    System.out.println("do post start");
    HttpSession session = request.getSession(true);
    System.out.println("got session"); // <== gets old value - not the
entered value!
    Test thisTest = (Test) session.getAttribute("test");
    System.out.println("entered value = " + thisTest.getName());
    session.setAttribute("test", thisTest);
    System.out.println("##### forwarding ##### ");

getServletConfig().getServletContext().getRequestDispatcher("/test.jsp").for
ward(request, response);
  }


### Test.java

public class Test extends Object {

  String name= new String("default");

  /**
   * Constructor
   */
  public Test() {
  }

  public void setName(String value) {
    name=value;
  }

  public String getName() {
    return name;
  }

}


The output is :

do post start
got session
entered value = default   <= HOW DO I GET THIS TO READ "BOB" INSTEAD
##### forwarding #####

I've tried using request scope instaed, but the
request.getAttribute("test") produces a null bean object - why?

Thanks in advance for any help - this has been bothering me for days!
Neil 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to