#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    15
    Rep Power
    0

    Unhappy jsp+form on same page


    i am developing a login form and i want the form and the jsp code on the same page,,,what is the form action to send the information to the same page,,,

    the page will be called query.jsp so would the following code work,,

    <FORM ACTION="query.jsp" METHOD="POST">

    is it as simple as referencing the same page?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Cambs, UK
    Posts
    68
    Rep Power
    13
    Well here's how I do it.....

    Code:
    <%
    if (request.getParameter("username") == null)
    {
      // Form hasn't been shown yet - display it
      out.println("<form action=\"query.jsp\" method=\"post\">");
      out.println("<input type=\"text\" name=\"username\" value=\"\">");
      // Rest of the form here
      out.println("</form>");
    }
    else
    {
      // Code here to process form here...
    }
    %>
    The first time the page is shown, the form doesn't exist when the java is executed, so request.getParameter.... returns null - so you display the form.

    Then when the form is submitted, the results are returned to itself (the page with the form on has to be in the ACTION part of the form tag). And this time the request.getParameter finds what it needs and processes the form input.

    Let me know if that didn't make sense.

IMN logo majestic logo threadwatch logo seochat tools logo