login.jsp页面
<body bgcolor="${requestScope.bg}" onload="${requestScope.welcome}"> <h${requestScope.h}>登录 </h${requestScope.h}> <form name="form1" method="post" action="loginservlet" onsubmit="return check()"> <br> 用户名:<input type="text" name="name" /> <br> <input type="submit" name="Submit" value="${empty requestScope.name?"提交":name}"> <input type="reset" value="Reset"><br /> ${requestScope.err}<br /> ${empty param.name?"":name} </form> </body>
|
loginservlet 的代码:
String name = request.getParameter("name"); if (name.equals("xiaoxiao")) { String err="返回 "; request.setAttribute("err",err); request.setAttribute("bg", "red"); request.setAttribute("h", "1"); request.setAttribute("welcome", "alert('欢迎您的登录!')"); request.setAttribute("name","登陆成功,欢迎小小"); request.getRequestDispatcher("login.jsp?name=123").forward(request, response); } else { String err="返回 "; request.setAttribute("err",err); request.setAttribute("bg", "blue"); request.setAttribute("h", "3"); request.setAttribute("name",name); request.setAttribute("welcome", "alert('欢迎BOY的登录!');"); request.getRequestDispatcher("login.jsp").forward(request, response);
}
|
程序虽然简单 但是可以举一反三 在很多地方应该很有用处,拿来和大家分享
阅读(672) | 评论(0) | 转发(0) |