Mapping the Servlet request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vijaykumardahiya
    New Member
    • Oct 2008
    • 11

    #1

    Mapping the Servlet request

    Dear Sir,
    I have two queries.
    First question is:
    I have a Html page. On which Have two buttons Submit and Issue.
    I want when I click on Sumit button request should be go to submit.jsp. and When I click on Issue button then request should be go to Issue.jsp.But When I click on submit button request do to Issue.jsp.
    Second Question is How I reterive the input parameter of html page to submit.jsp.
    Please review..

    My files are:
    login.html:
    [code=html]
    <html>
    <head>
    <title>A simple JSP application</title>
    <head>
    <body>
    <form method="get" action="tmp">
    Name<input type="text" name="user">
    <br>
    Password<input type="password" name="pass">
    <input type="Submit" value="Submit">
    <input type="Submit" value="Issue">
    </form>
    </body>
    </html>
    [/code]
    LoginServlet.ja va:[code=java]
    import java.io.*;
    import javax.servlet.* ;
    import javax.servlet.h ttp.*;
    import java.sql.*;
    import java.util.*;
    public class LoginServlet extends HttpServlet{
    public void doGet(HttpServl etRequest request, HttpServletResp onse response)
    throws ServletExceptio n,IOException{
    try
    {
    response.setCon tentType("text/html");
    PrintWriter out=response.ge tWriter();
    String user=request.ge tParameter("use r");
    String pass=request.ge tParameter("pas s");
    out.println("He llo: "+user);
    out.println("He llo: "+pass);

    RequestDispatch er dispatcher1 =
    request.getRequ estDispatcher("/Issue.jsp");
    dispatcher1.for ward(request,re sponse);

    RequestDispatch er dispatcher =
    request.getRequ estDispatcher("/submit.jsp");
    dispatcher.forw ard(request,res ponse);
    }
    catch(Exception e)
    {
    e.printStackTra ce();
    }
    }
    }[/code]

    web.xml:[code=xml]
    <web-app>

    <servlet>
    <servlet-name>one</servlet-name>
    <servlet-class>LoginServ let</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>one</servlet-name>
    <url-pattern>/tmp</url-pattern>
    </servlet-mapping>

    <jsp-file>submit.jsp </jsp-file>
    <jsp-file>Issue.jsp</jsp-file>
    <url-pattern>*.do</url-pattern>

    <welcome-file-list>
    <welcome-file>Login.html </welcome-file>
    </welcome-file-list>

    </web-app>[/code]
    Last edited by Nepomuk; Oct 13 '08, 08:43 AM. Reason: Added [CODE] tags
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    answer 1:
    in your HTML-form-tag, the action must be set to point to your webpage and not to "tmp".

    answer 2:
    by calling
    request.getPara meter("user")

    Comment

    • vijaykumardahiya
      New Member
      • Oct 2008
      • 11

      #3
      Originally posted by chaarmann
      answer 1:
      in your HTML-form-tag, the action must be set to point to your webpage and not to "tmp".

      answer 2:
      by calling
      request.getPara meter("user")

      Dear Sir,
      In Answer 1:
      Whether Its only solution is Java-Script.? so that on Html page when I click on Submit button request go to Submit.jsp or when I click on Issue button request go to issue.jsp

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by vijaykumardahiy a
        Dear Sir,
        In Answer 1:
        Whether Its only solution is Java-Script.? so that on Html page when I click on Submit button request go to Submit.jsp or when I click on Issue button request go to issue.jsp
        Why not have one jsp handle both options? e.g.

        Code:
        <INPUT TYPE=SUBMIT NAME="button" VALUE="submit"> 
        <INPUT TYPE=SUBMIT NAME="button" VALUE="issue">
        Your single jsp would receive one parameter "button" with a value "submit" or
        "issue". It can make a decision based on that criteria.

        kind regards,

        Jos

        Comment

        Working...