March 3rd, 2003, 04:40 PM
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?
March 4th, 2003, 09:02 AM
Well here's how I do it.....
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.
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
// Code here to process form here...
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.