Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't override the doGet method.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everybody. Now Servlet is working.
 
jyothi sanka
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TOMCAT_HOME/webapps/YOUR_WEBAPP/WEB-INF/classes/YOUR_PACKAGE/YOUR_CLASS
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want clear explonation for this problem please!!!what is the need of doGet() here???
 
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple enough. If you want your servlet to service GET requests, you override doGet(). Problem solved.
 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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..
 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic