这个问题在这里已经有答案了:
servlet返回“http状态404请求的资源(/servlet)不可用”(16个答案)
四年前关门了。
我有一个signin.jsp,允许用户登录他们的帐户。这个html表单将生成一个javaservlet。它在本地工作,但在我购买的付费网络主机服务器上不工作。它一直给我一个惊喜 404 error /LoginServlet cannot be found.
提前谢谢!
下面是我的jsp:
<form action="LoginServlet" method="POST" style="background-color: transparent;">
<input type="text" id="username" name="username" placeholder="Username" style=" height: 25px" value=""/>
<input type="password" id="password" name="password" placeholder="Password" style=" height: 25px" value=""/>
<input type="submit" name="submit" class=" login-submit" value="Sign-In" style=" height: 25px" />
</form>
下面是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<display-name>ThinkAuction</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>User.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
下面是我的loginservlet:
public class LoginServlet extends HttpServlet {
//private static final long serialVersionUID = 1L;
static private int loginSuccessful = 0; etc...}
1条答案
按热度按时间bd1hkmkf1#
将表单标记中动作属性的值更改为
${pageContext.request.contextPath}/LoginServlet
.${pageContext.request.contextPath}
返回指示请求上下文的请求uri部分。它与
request.getContextPath()
<form action="${pageContext.request.contextPath}/LoginServlet" method="POST" style="background-color: transparent;">