This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, I have a problem in request forwarding which I find strange. I am forwarding request to a HTML page.When I request a servlet from browser directly (which invokes doGet(..) method of the servlet) the HTML page to which I am forwarding the request is served to browser. But when I created a form which invokes doPost(..) method of the same servlet, the code(same code which works in doGet(..))to forward request to HTML page is not working. Then I tried to call doGet(..) from doPost(..) so that the code which works when I directly call servlet from browser is invoked. Again, it is not working. The code is as follows : import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class TrialServlet extends HttpServlet {
//invoked when this servlet is directly launched from browser.
I wish somebody helps me. This is important for the project I am doing. I am posting the code below. I hope I have been able to explain the problem clearly. Thanks a lot.
Milind.
madhu babu
Greenhorn
Joined: Jan 08, 2001
Posts: 6
posted
0
hai, doPost() mehtod is used for sending data from server to client. what ever method GET or POST it is handled by doGet() method only executed. see small example:/* servlet**** import javax.servlet.*; import java.io.*; import javax.servlet.http.*; public class post extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException { PrintWriter out=res.getWriter(); out.println("this is madhu"); } public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException { doPost(req,res); } } */ *****html page*** <html> <body> <form method=post action="servlet/post"> <input type=submit value=submit> </form> </body> </html>
Milind Mahajan
Ranch Hand
Joined: Oct 23, 2000
Posts: 77
posted
0
Hi, Thanks for the response Madhu. I agree with you. But my doubt about request forwarding in doGet(..) and doPost(..) persists. Can somebody help me please? Thanks , Milind
Katie McCann
Ranch Hand
Joined: Jul 24, 2000
Posts: 45
posted
0
Rename the .html file you are forwarding to to "Thanks.jsp". I think this will solve your problem. Post requests can't be forwarded to plain HTML pages, and the solution is to rename it with a .jsp extension. If you own the "Core Servlets..." book see page 355 for an explanation.
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Quite strange, since reading the RequestDispatcher API for the forward() method, doesn't say anything. Textbooks always help, don't they? Regds. - satya