Reputation: 1
I'm using eclipse to develop a Google App Engine application. I am on a login page, but I click login, then it shows "Error 405 HTTP method POST is not supported by this URL"?
Here is my servlet code:
my LgServlet.java:
package com.lan;
import java.io.IOException;
import javax.servlet.http.*;
public class LgServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void doPost(HttpServletRequest req,HttpServletResponse resp)
throws IOException {
check(req,resp);
}
@Override
public void doGet(HttpServletRequest req,HttpServletResponse resp)
throws IOException {
check(req,resp);
}
public void check(HttpServletRequest req,HttpServletResponse resp)
throws IOException {
if(req.getAttribute("userID").equals("admin")&&req.getAttribute("userPassword").equals("123456")){
resp.setContentType("text/plain");
resp.getWriter().println("Hello Admin");
}
}
}
my web.xml:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>lg</servlet-name>
<servlet-class>com.lan.LgServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>lg</servlet-name>
<url-pattern>/lg</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
part of index.jsp:
<form action="lg" method="post">
I hope someone can help explain to me why I'm getting this error?
Thanks!
Upvotes: 0
Views: 678
Reputation: 11
Try changing
<form action="lg" method="post">
to
<form action="/lg" method="post">
Nothing else looks out of place. I got this error recently, but it was because i was calling super.doPost() in my doPost call.
HTH
Upvotes: 1