Results 1 to 3 of 3
  1. #1
    Bores is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default jsp forward question

    Hi

    I want to forward the post request of my form to the servlet LoginServlet exactly as if I make action="LoginServlet" in my form. My form is in LoginForm.jsp and this is my approach :

    Content of LoginForm.jsp
    Java Code:
    <%  
    if (request.getMethod().equals("POST"))  
    {  
    // ...  Some checks
    <jsp:forward page="/LoginServlet"/>  
    }  
    %>
    <form action="LoginForm.jsp">  
    <input type="text" name="username">  
    <input type="password" name="userpass">  
    <input type="submit" value="submit">  
    </form>
    So I don't know about the slash in the <jsp:forward page="/LoginServlet"/> if it is mandatory or useless. The LoginServlet servlet should be able to capture the post data with doPost and doGet procedures.

    Regards

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: jsp forward question

    This should really be in a Servlet you know.
    The form would target the LoginServlet and the servlet would validate and forward either to the main page of whatever it is they are logging into, or back to the login page with a message saying failed to login.
    It's cleaner, easier to write, easier to debug, and means you don't need to clutter up your JSP with code.
    Please do not ask for code as refusal often offends.

  3. #3
    nicephotog is offline Member
    Join Date
    Mar 2012
    Posts
    41
    Rep Power
    0

    Default Re: jsp forward question

    First, that requires step over scripting
    <%
    if (request.getMethod().equals("POST"))
    {
    // ... Some checks
    %>

    <jsp:forward page="LoginServlet"/>

    <%
    }
    %>


    second , basic jsp calls to a page are "GET" method so you do not need that system

    <form action="LoginServlet" method="POST">
    <input type="text" name="username">
    <input type="password" name="userpass">
    <input type="submit" value="submit">
    </form>

    Would need to be a GET method because of implicit method= type of form
    <jsp:forward page="LoginServlet">
    <jsp:param name="username" value="text" />
    <jsp:param name="userpass" value="password" />
    </jsp:forward>

Similar Threads

  1. jsp:forward problem
    By Lutra in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-22-2011, 07:00 PM
  2. Forward references
    By Norm in forum Advanced Java
    Replies: 2
    Last Post: 06-30-2010, 02:19 AM
  3. jsp:forward vs jsp:redirect / XML tag if
    By lse123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-25-2010, 08:23 AM
  4. Replies: 5
    Last Post: 07-29-2008, 02:13 PM
  5. jsp:forward action
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 10:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •