写了一个Servlet模拟登陆的Demo,但是运行tomcat之后,登陆网址出现500错误,刷新之后又出现404错误,如何解决
html能够登陆,跳转之后出现404
这是项目结构:
首先你form表单应该写明method是get还是post(虽然应该不是这个问题),其次你web.xml的配置LoginServlet不用加包名?暂时就只能看到这两个问题。太久没写后台了,说错请见谅233
这是 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" 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">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
</web-app>
以及Servlet类:
package com.Demo;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println("username = " + username);
System.out.println("password = " + password);
response.setContentType("text/html");
response.getWriter().println("Login Success");
}
}
对应项目结构:
有没有dalao来看一下啊,在这个地方卡了一天了
tomcat版本是7.0,使用的JDK版本是1.6
开发工具是使用的MyEclipse,创建项目的时候是new Web Project
所以楼主最后怎么解决的啊?
这是Login.html:
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
</head>
<body>
<form action="http://localhost:8080/LoginDemo/loginServlet">
UserName: <input type="text" name="username" value="your username here" > <br/>
PassWord: <input type="password" name="password" value="your password here"> <br/>
<input type="submit" value="登录">
</form>
</body>
</html>