aspose file tools*
The moose likes Servlets and the fly likes Status 405 - 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 "Status 405 - HTTP method GET is not supported by this URL" Watch "Status 405 - HTTP method GET is not supported by this URL" New topic
Author

Status 405 - HTTP method GET is not supported by this URL

jyothi sanka
Ranch Hand

Joined: Aug 27, 2001
Posts: 39
Hi,
I am reading HF servlet jsp book.I want to run the Code in chapter 8 and I am getting HTTP method GET is not supported by this URL

error while ...

servlet code is:

public class PersonObject extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException{
Person p = new Person();
p.setName("Evan");

request.setAttribute("person", p);

RequestDispatcher view = request.getRequestDispatcher("/result.jsp");
view.forward(request, response);

}
}

person class:
public class Person
{
private String name;
public String getName(){return name;
}
public void setName(String name){
this.name= name;
}
}

result.jsp
<html><body>
Person is : <%= request.getAttribute("person") %>
</body></html>
web.xml

<web-app>
<servlet-name>PersonObject</servlet-name>
<servlet-class>PersonObject</servlet-class>
<!-- Resources bundle base class -->
</servlet>
<servlet-mapping>
<servlet-name>PersonObject</servlet-name>
<url-pattern>/PersonObject.do</url-pattern>
</servlet-mapping>
</web-app>

I wrote servlet code and everything like that and I tried to open servlet page using this url [URL=http://localhost:8080/HFchapter5/PersonObject.do]

but I am getting error like this
HTTP Status 405 - HTTP method GET is not supported by this URL
message HTTP method GET is not supported by this URL

Can anybody explain me where I did wrong?
Thak you
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You didn't override the doGet method.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Jyothi,
Allow me to elaborate on what Ben said.

The "PersonObject" class needs to have a "doGet()" method.
If you want the "doGet()" method to do exactly the same thing as the "doPost()" method does, then your "doGet()" method can simply be:

Good Luck,
Avi.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
Just one more point -
using this url [URL=http://localhost:8080/HFchapter5/PersonObject.do]

always causes a GET type request. The typical way to do a POST type request is with an HTML form where the form tag has method="POST"
jyothi sanka
Ranch Hand

Joined: Aug 27, 2001
Posts: 39
Thank you everybody. Now Servlet is working.
jyothi sanka
Ranch Hand

Joined: Aug 27, 2001
Posts: 39
Hi, That one is worked when we use string Attribute. But when I tried to access JavaBean class jsp can't access the bean class.
I am using Eclipse and Tomcat with SysDeo tomcat plugin for creating Tomcat project.
This is my directory:
Package HFChapter5:
I wrote PersonObject servlet class and Person Bean class in this directory web-inf/src .
I wrote result.jsp in HFChapter5. jsp is not able to find the Bean class? Where do I have to write Bean class?
Thank you
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

TOMCAT_HOME/webapps/YOUR_WEBAPP/WEB-INF/classes/YOUR_PACKAGE/YOUR_CLASS
naresh kumar mallala
Greenhorn

Joined: Jun 13, 2011
Posts: 21
I want clear explonation for this problem please!!!what is the need of doGet() here???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61774
    
  67

Simple enough. If you want your servlet to service GET requests, you override doGet(). Problem solved.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

William Brogden wrote:Just one more point -
using this url [URL=http://localhost:8080/HFchapter5/PersonObject.do]

always causes a GET type request. The typical way to do a POST type request is with an HTML form where the form tag has method="POST"


but now i am getting "HTTP Status 405 - HTTP method POST is not supported by this URL"
please help me out..
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Have you overwritten the method doPost in your servlet? You have to overwrite the type of supporting method which you used at HTML form method type.


No pain, No gain.
OCJP 1.6
sridhar sivaraman
Greenhorn

Joined: Mar 02, 2012
Posts: 13
hi,
your HttpServlet mostly uses any one of the HTTP methods as GET or POST

for every HTML page the default method taken for <form .... method="GET"> is GET
Even if you declare it or not...
You have to declare post if you are handling a post request

so for supporting both the methods, it'll be better to override both the methods in your servlet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Status 405 - HTTP method GET is not supported by this URL