一个HTML页面+servlet类,实现基本动态网页
/**
* 登录验证servlet类
* @author cww
*
*/
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
//获取用户名密码
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println("用户名" + username);
System.out.println("密码" + password);
response.setContentType("text/html;charset=UTF-8");
//获取指定客户端流
PrintWriter out = response.getWriter();
//根据情况动态生成一个网页响应客户端
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>用户登录结果</TITLE></HEAD>");
out.println(" <BODY>");
if("abc".equals(username)&& "123".equals(password)){
out.println("<center><h1>用户登录成功</h1></center>");
}else {
out.println("<center><h1>用户登录失败</h1></center>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>块状标签(用户登录)演示</title>
</head>
<body>
<center><h1>学院管理系统</h1></center>
<form action="LoginServlet" method="post">
<table border="0" align="center" width="68%">
<tr>
<td align="right" width="35%">用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td></td>
<td>
<input type="reset" value="重置"/>
<input type="submit" value="登录"/>
</td>
</tr>
</table>
</form>
</body>
</html>
版权声明:本文为qq_39089814原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。