I am getting the subjected error, could you please help
servlet
public class FirstClass extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
PrintWriter out = response.getWriter();
out.println("this is a sample");
out.flush();
}
public void doPost(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
PrintWriter out = response.getWriter();
out.println("this is a sample");
out.flush();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>hii</display-name>
<servlet>
<servlet-name>First</servlet-name>
<servlet-class>test.FirstClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/first.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="first.do">Click Me</a>
</body>
</html>
It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the target resource.
The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn't support this method.
The 405 HTTP Status Code means that the method is not allowed. In the 405 HTTP Status Code, the Request-Line isn't considered the resource distinguished by the Request-URI. The response should incorporate an Allow header containing a rundown of substantial strategies for the mentioned asset.
You've got the parameters the wrong way round - it should be the request first, then the response, like this:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
So currently you're not actually overriding the superclass method.
This is why the @Override
annotation is so important - it lets you find bugs like this at compile time. If you'd decorated your method with @Override
, the compiler would have spotted that you were trying to override a method signature which didn't exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With