This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
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: 18570
    
    8

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: 61298
    
  66

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] [Bear's FrontMan] [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: http://aspose.com/file-tools
 
subject: HTTP method GET is not supported by this URL