• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP method GET is not supported by this URL

 
Venkata Pavan Kumar vemuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21155
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, if you want serve both requests, override both doGet() and doPost() methods. The service() method will handle your request appropriately.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic