Results 1 to 2 of 2
- 03-27-2011, 12:53 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 25
- Rep Power
- 0
How to handling submit button from servlet
hi all.....
i have problem during handling button from my servlet .when i click button 3 ,
servlet not forward to outputControl.jsp .But for button1 ,there work well .
what's the kind problem there ? hope some one can show me the best way to do that .i have a more button in JSP that i want to handle from servlet .
all help ,would be appreciated.
code like bellow :
index.jsp :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="mainform" action="servletControl" method="POST">
<input type="submit" value="button1" name="button1" />
<input type="submit" value="button2" name="button1" />
<input type="submit" value="button3" name="button3" />
</form>
</body>
</html>
servletControl :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String button1Click = request.getParameter("button1");
String button3Click = request.getParameter("button3");
try {
if(button1Click.equalsIgnoreCase("button1")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
if(button1Click.equalsIgnoreCase("button2")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
if(button3Click.equalsIgnoreCase("button3")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
} finally {
out.close();
}
}
- 03-27-2011, 03:10 PM #2
Member
- Join Date
- Aug 2010
- Posts
- 25
- Rep Power
- 0
is there any body know ?i have try with different button name and make form /each button .but only work for button 1. i don't know how to solve this ......
index.jsp :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="mainform" action="servletControl" method="POST">
<input type="submit" value="button1" name="button1" />
</form>
<form name="mainform" action="servletControl" method="POST">
<input type="submit" value="button2" name="button2" />
</form>
<form name="mainform" action="servletControl" method="POST">
<input type="submit" value="button3" name="button3" />
</form>
</body>
</html>
servletControl:
if(button1Click.equals("button1")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
if(button2Click.equals("button2")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
if(button3Click.equals("button3")){
RequestDispatcher dispatcher = request.getRequestDispatcher("/outputControl.jsp");
dispatcher.forward( request, response);
}
Similar Threads
-
JSP program to handle submit button
By gurpreet.singh in forum JavaServer Pages (JSP) and JSTLReplies: 6Last Post: 03-09-2011, 05:46 AM -
passing data to two servlets uing one submit button
By Cashley in forum Java ServletReplies: 2Last Post: 04-12-2010, 01:41 PM -
invoking servlet from jsp form submit using web.xml
By java_hyd in forum Java ServletReplies: 1Last Post: 11-24-2009, 08:57 PM -
Submit Button Help
By Jay-1.1 in forum New To JavaReplies: 2Last Post: 05-06-2008, 04:28 PM -
Display success message in same page when submit button is clicked
By am17mu in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-29-2008, 10:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks