Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP status 405 Error

 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Person.class is in D:\Tomcat4.1\webapps\foo\WEB-INF\classes

package foo;
public class Person{
private String name;

public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
}

BeanEx.class is in D:\Tomcat4.1\webapps\foo\WEB-INF\classes

package foo;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeanEx extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException {
foo.Person p = new foo.Person();
p.setName("Evan");
request.setAttribute("person",p);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

result.jsp in D:\Tomcat4.1\webapps\foo

<html>
<body>
person is: <%= request.getAttribute("person") %>
</body>
</html>

web.xml in D:\Tomcat4.1\webapps\foo\WEB-INF

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>BeanPerson</servlet-name>
<servlet-class>foo.BeanEx</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BeanPerson</servlet-name>
<url-pattern>/Tester.do</url-pattern>
</servlet-mapping>
</web-app>

http://localhost:8080/foo/Tester.do is giving the error

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

where is it going wrong?
 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,

Obviously your servlet doesn't implement doGet method, that's why you are getting error while accessing http://localhost:8080/foo/Tester.do through browser.Whenever we access some thing directly on the browser, GET method will be triggered.

So try calling the Tester.do from html page like below then POST will be triggered.

<html><body>
<form name="test" action="Tester.do" method="POST">
<input type=submit>
</form>
<body></html>
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanku Raju, i forgot that Get is the default...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic