当我启动 loginPage.jsp 表单并输入用户名和密码时出现此错误:
type Status report
message /WHFM/LoginServlet.java
description The requested resource is not available.
我错过了什么?我读过关于同样问题的文章,但我认为区分大小写是正确的,在这里。
<form name="loginForm" method="Post" action="LoginServlet.java">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="uname"></td></tr>
<tr><td>Password:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr><td></td><td><input type="submit" value="submit" name="submit"></td></tr>
</table>
</form>
和servlet是:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DBConnection connString = new DBConnection();
String query = "";
String username= request.getParameter("uname");
String password = request.getParameter("pass");
int counter= 0;
try {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
connString.getConnection();
query="Select * from user where username='"+username+"' and password='"+password+"' ";
System.out.println(query);
Statement st = connString.getConnection().createStatement();
ResultSet rs= st.executeQuery(query);
while(rs.next()){
counter++;
}
if(counter>0){
response.sendRedirect("welcome.jsp");
}
else{
response.sendRedirect("LoginPage.jsp");
}
这是我的 XML:
<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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>WHFM</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlets.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServletPath</url-pattern>
</servlet-mapping>
</web-app>