input
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>用户登录</title> </head> <body> <form name="form1" method="post" action="control.jsp"> <table align="center"> <tr> <td> 用户名:<input type="text" name="userName" /> 密码:<input type="password" name="pwd" /> <input type="submit" value="登录" /> </td> </tr> </table> </form> </body> </html>
?
control
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>登录处理页面</title> </head> <body> <% request.setCharacterEncoding("utf-8"); String name = request.getParameter("userName"); String pwd = request.getParameter("pwd"); if(name.trim().equals("chaoyi") && pwd.trim().equals("123456")){ request.getRequestDispatcher("welcome.jsp").forward(request,response); }else{ out.print("<script>alert('登录失败');history.back()</script>"); } %> </body> </html>
?
welcome
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>欢迎</title> </head> <body> 欢迎您:<%=request.getParameter("userName")%> </body> </html>
?
效果图:
?
?
?