我有一个signIn.jsp,允许用户登录他们的帐户。这个HTML表单将导致一个java servlet。它在本地工作但不适用于我购买的付费网络主机服务器。它提前给了我一个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...}
答案 0 :(得分:0)
将表单标记中操作属性的值更改为${pageContext.request.contextPath}/LoginServlet
。
${pageContext.request.contextPath}
返回请求URI的一部分,指示请求的上下文。
与request.getContextPath()
<form action="${pageContext.request.contextPath}/LoginServlet" method="POST" style="background-color: transparent;">