| Author |
HTTP method GET is not supported by this URL
|
Venkata Pavan Kumar vemuri
Greenhorn
Joined: Feb 01, 2010
Posts: 14
|
|
hi I have the following servlet code written and im getting the "HTTP method GET is not supported by this URL" error can some one help me with this
package servpack;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class SampleServlet
*/
public class SampleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public SampleServlet() {
// TODO Auto-generated constructor stub
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(request, response);
RequestDispatcher dis;
dis = request.getRequestDispatcher("welcome.jsp");
dis.forward(request, response);
}
}
Thanks in advance
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
|
It's simple. If you want the servlet to respond to POST requests then you must implement the doPost() method. And if you want it to respond to GET requests then you must implement the doGet() method.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56173
|
|
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.
Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
And, if you want serve both requests, override both doGet() and doPost() methods. The service() method will handle your request appropriately.
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: HTTP method GET is not supported by this URL
|
|
|