By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

Mapping the Servlet request

P: 11
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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>A simple JSP application</title>
  4. <head>
  5. <body>
  6. <form method="get" action="tmp">
  7. Name<input type="text" name="user">
  8. <br>
  9. Password<input type="password" name="pass">
  10. <input type="Submit" value="Submit">
  11. <input type="Submit" value="Issue">
  12. </form>
  13. </body>
  14. </html>
  15.  
LoginServlet.java:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. import java.sql.*;
  5. import java.util.*;
  6. public class LoginServlet extends HttpServlet{ 
  7. public void doGet(HttpServletRequest request, HttpServletResponse response)
  8. throws ServletException,IOException{
  9. try
  10. {
  11. response.setContentType("text/html");
  12. PrintWriter out=response.getWriter();
  13. String user=request.getParameter("user");
  14. String pass=request.getParameter("pass");
  15. out.println("Hello: "+user);
  16. out.println("Hello: "+pass);
  17.  
  18. RequestDispatcher dispatcher1 = 
  19. request.getRequestDispatcher("/Issue.jsp");
  20. dispatcher1.forward(request,response);
  21.  
  22. RequestDispatcher dispatcher = 
  23. request.getRequestDispatcher("/submit.jsp");
  24. dispatcher.forward(request,response);
  25. }
  26. catch(Exception e)
  27. {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
web.xml:
Expand|Select|Wrap|Line Numbers
  1. <web-app>
  2.  
  3. <servlet>
  4. <servlet-name>one</servlet-name>
  5. <servlet-class>LoginServlet</servlet-class>
  6. </servlet>
  7. <servlet-mapping>
  8. <servlet-name>one</servlet-name>
  9. <url-pattern>/tmp</url-pattern>
  10. </servlet-mapping>
  11.  
  12. <jsp-file>submit.jsp</jsp-file>
  13. <jsp-file>Issue.jsp</jsp-file>
  14. <url-pattern>*.do</url-pattern>
  15.  
  16. <welcome-file-list>
  17. <welcome-file>Login.html</welcome-file>
  18. </welcome-file-list>
  19.  
  20. </web-app>
Oct 11 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 785
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.getParameter("user")
Oct 14 '08 #2

P: 11
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.getParameter("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
Oct 17 '08 #3

Expert 10K+
P: 11,448
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.

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE=SUBMIT NAME="button" VALUE="submit"> 
  2. <INPUT TYPE=SUBMIT NAME="button" VALUE="issue"> 
  3.  
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
Oct 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.