代码如下://运行有错误
Html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Login</title>
</head>
<body>
<form Action="Login" method="post">
用户名:<input type="text" name="user">
密码: <input type="password" name="password">
</form>
</body>
</html>
//Action是什么?
//类 Display
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Display extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
public Display() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("test/html;charset=GBK");
String user = (String)request.getParameter("user");
if(user!=null)
{
response.getWriter().println("欢迎你"+user);
}
else
{
response.getWriter().println("请登陆");
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
}
//类SessionInfo
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SessionInfo extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
public SessionInfo() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html,charset=GBK");
String user = request.getParameter("uesr");
HttpSession session = request.getSession();
if(user.length()>0)
{
session.setAttribute("user", user);//这2 个user分别是哪个?
}
RequestDispatcher rd = request.getRequestDispatcher("display");
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}