This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jyothi sanka
Ranch Hand
Posts: 39
  • 0
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't override the doGet method.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • 0
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everybody. Now Servlet is working.
 
jyothi sanka
Ranch Hand
Posts: 39
  • 0
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TOMCAT_HOME/webapps/YOUR_WEBAPP/WEB-INF/classes/YOUR_PACKAGE/YOUR_CLASS
 
naresh kumar mallala
Greenhorn
Posts: 21
  • 0
  • 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???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • 0
  • 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..
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • 0
  • 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.
 
sridhar sivaraman
Greenhorn
Posts: 13
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic