JSP登录页面大小
1 <%-- 2 Created by IntelliJ IDEA. 3 User: SuSh1 4 Date: 2019/9/27 5 Time: 12:03 6 To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 <html> 10 <head> 11 <title>注册</title> 12 13 <style> 14 span{ 15 color: red; 16 } 17 </style> 18 </head> 19 <body> 20 <form action="doUserLogin.jsp"method="post"> 21 22 账号: <input type="text"name="userName"placeholder="请输入账号"><span>*</span><br/> 23 密码: <input type="password"name="password"placeholder="请输入密码"><span>*</span><br/> 24 25 <input type="submit"value="登录"> 26 </form> 27 <% 28 String info = request.getParameter("info"); 29 if(info !=null){ 30 out.print(info); 31 } 32 Integer count = (Integer)application.getAttribute("count"); 33 if(count==null){ 34 //application中还没有count 35 application.setAttribute("count",1); 36 }else { 37 //application已有count 38 39 application.setAttribute("count",count+1); 40 } 41 Integer icount=(Integer)application.getAttribute("count"); 42 out.print("页面已经访问"+icount+"次"); 43 44 %> 45 46 47 </body> 48 </html>
1 <%@ page import="java.net.URLEncoder" %><%-- 2 Created by IntelliJ IDEA. 3 User: SuSh1 4 Date: 2019/9/27 5 Time: 12:04 6 To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 <html> 10 <head> 11 <title>验证注册</title> 12 </head> 13 <body> 14 <% 15 request.setCharacterEncoding("UTF-8"); 16 String userName = request.getParameter("userName"); 17 String password = request.getParameter("password"); 18 19 if(userName.equals("admin")&&password.equals("123")){ 20 //转发 21 session.setAttribute("userName",userName); 22 Cookie cookie = new Cookie("userName",userName); 23 cookie.setPath("/"); 24 response.addCookie(cookie); 25 request.getRequestDispatcher("LoginSuccess.jsp").forward(request,response); 26 27 }else{ 28 //重定向 29 String info = "登录失败!"; 30 info = URLEncoder.encode(info,"utf-8"); 31 response.sendRedirect("userLogin.jsp?info="+info); 32 } 33 %> 34 <% 35 36 37 %> 38 </body> 39 </html>
1 <%-- 2 Created by IntelliJ IDEA. 3 User: SuSh1 4 Date: 2019/9/28 5 Time: 18:09 6 To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 <html> 10 <head> 11 <title>Title</title> 12 </head> 13 <body> 14 <% 15 String userName = (String) session.getAttribute("userName"); 16 if(userName==null&&userName==""){ 17 response.sendRedirect("userLogin.jsp"); 18 }else{ 19 %> 20 <h1>欢迎<%=userName%>登录成功</h1> 21 <%} 22 23 %> 24 25 </body> 26 </html>