This discussion is archived
3 Replies Latest reply: Mar 24, 2012 11:04 AM by 919944 RSS

form post parameters

924984 Newbie
Currently Being Moderated
Hi
I have a form.jsp file which has the following :


<form action="LoginServlet">
<input type="text" name="username">
<input type="password" name="userpass">
<input type="submit" value="submit">
</form>
<%
if (request.getMethod().equals("POST"))

// ...
}
%>


The form post data are sent to LoginServlet as usual but I want to be able to catch the form data in the form.jsp file itself exactly as php does. I am surprised way php has this feature where jsp no!! Because I want to use the form data to process some tasks in form.jsp as well as sending the user to LoginServlet.

Regards

Edited by: 921981 on Mar 19, 2012 4:53 PM

Edited by: 921981 on Mar 19, 2012 4:55 PM
  • 1. Re: form post parameters
    EJP Guru
    Currently Being Moderated
    I am surprised way php has this feature where jsp no!!
    I'd be surprised too. I'm even more surprised that you think JSP doesn't have it when it does. How exactly do you think all those millions of JSP web-apps actually work?

    See request.getParameter().
  • 2. Re: form post parameters
    924984 Newbie
    Currently Being Moderated
    Hi
    I have a question regarding forward method in jsp, the form now have changed so it send the data into itself form.jsp rather than LoginServlet servlet. Because I want to verify some tasks before sending the post request into the servlet :

    I have a form.jsp file which has the following :

    <%
    if (request.getMethod().equals("POST"))
    {
    // ...
    <jsp:forward page="/LoginServ"/>
    %>
    <form action="form.jsp">
    <input type="text" name="username">
    <input type="password" name="userpass">
    <input type="submit" value="submit">
    </form>

    So what I want to do is that if there is a post request which mean the user click the submit button than redirect the post request to LoginServ Servlet and this servlet will proceed the post request that the user make, so does this code will do the job right exactly as if there is action=LoginServ ? and for the slash is it mandatory ?
    <jsp:forward page="/LoginServ"/> OR <jsp:forward page="LoginServ"/>

    Thank you
  • 3. Re: form post parameters
    919944 Newbie
    Currently Being Moderated
    921981 wrote:

    <%
    if (request.getMethod().equals("POST"))
    {
    // ...
    <jsp:forward page="/LoginServ"/>
    %>
    Not like that. The <jsp:forward> tag cannot be put inside scriptlet like that. I should be mixed with HTML code.

    >
    So what I want to do is that if there is a post request which mean the user click the submit button than redirect the post request to LoginServ Servlet and this servlet will proceed the post request that the user make, so does this code will do the job right exactly as if there is action=LoginServ ? and for the slash is it mandatory ?
    <jsp:forward page="/LoginServ"/> OR <jsp:forward page="LoginServ"/>
    The slash is not mandatory. if specified, the path is relative to the web application's root. Otherwise, the path is relative to the current page.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points