JSP登录页面大小

Lev1 2019-09-28 22:52:00
原文地址:https://www.cnblogs.com/lev1/p/11605334.html

![]()![]() ```
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>


 客户端userLogin

![]()![]() ```
 1 &lt;%@ page import=&quot;java.net.URLEncoder&quot; %&gt;&lt;%--
 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 --%&gt;
 8 &lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;
 9 &lt;html&gt;
10 &lt;head&gt;
11     &lt;title&gt;验证注册&lt;/title&gt;
12 &lt;/head&gt;
13 &lt;body&gt;
14 &lt;%
15     request.setCharacterEncoding(&quot;UTF-8&quot;);
16     String userName = request.getParameter(&quot;userName&quot;);
17     String password = request.getParameter(&quot;password&quot;);
18 
19     if(userName.equals(&quot;admin&quot;)&amp;&amp;password.equals(&quot;123&quot;)){
20         //转发
21         session.setAttribute(&quot;userName&quot;,userName);
22         Cookie cookie = new Cookie(&quot;userName&quot;,userName);
23         cookie.setPath(&quot;/&quot;);
24         response.addCookie(cookie);
25         request.getRequestDispatcher(&quot;LoginSuccess.jsp&quot;).forward(request,response);
26 
27     }else{
28         //重定向
29         String info = &quot;登录失败!&quot;;
30         info = URLEncoder.encode(info,&quot;utf-8&quot;);
31         response.sendRedirect(&quot;userLogin.jsp?info=&quot;+info);
32     }
33 %&gt;
34 &lt;%
35 
36 
37 %&gt;
38 &lt;/body&gt;
39 &lt;/html&gt;

服务器端doUserLogin

![]()![]() ```
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>



 登录成功界面

声明:该文章系转载,转载该文章的目的在于更广泛的传递信息,并不代表本网站赞同其观点,文章内容仅供参考。

本站是一个个人学习和交流平台,网站上部分文章为网站管理员和网友从相关媒体转载而来,并不用于任何商业目的,内容为作者个人观点, 并不代表本网站赞同其观点和对其真实性负责。

我们已经尽可能的对作者和来源进行了通告,但是可能由于能力有限或疏忽,导致作者和来源有误,亦可能您并不期望您的作品在我们的网站上发布。我们为这些问题向您致歉,如果您在我站上发现此类问题,请及时联系我们,我们将根据您的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。