File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HTTP method GET is not supported by this URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP method GET is not supported by this URL " Watch "HTTP method GET is not supported by this URL " New topic

HTTP method GET is not supported by this URL

Venkata Pavan Kumar vemuri

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 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

* @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

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Jan 10, 2002
Posts: 63844

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.

[Asking smart questions] [About Bear] [Books by 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:
subject: HTTP method GET is not supported by this URL
It's not a secret anymore!