html程序是这样的
<html>
<head> <title>Login Page</title> </head>
<body>
<form action="login1" method="post">
<table width="298" border="0" align="center"
cellpading="2" cellspacing="1">
<tr>
<td align="right">用户名:</td>
<td align="left"><input type="text" name="username" ></td>
</tr>
<tr>
<td align="right">密 码:</td>
<td><input type="password" name="password" ></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录">
<input type="reset" value="取消"></td>
</tr>
</form>
</body>
</html>
servlet程序是这样的:
import *;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
out.println("<html><body>");
if(username.equals("admin")&&password.equals("admin")){
out.println("登录成功!欢迎您, "+username);
}else{
out.println("对不起!您的用户名或密码不正确.");
}
out.println("</body></html>");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
}