第8次

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
  
    <%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <script type="text/javascript">
        function yz(){
            if (fm.uname.value=="") {
                alert("请输入账号");
                return;
            }
            else if (fm.pas.value=="") {
                alert("请输入密码");
                return;
            }
            fm.submit();
        }
    </script>
   
  <body>
  <form action="logindo.jsp" name="fm">
    用户名:<input type="text" name="uname" />
     密码:<input type="password" name="pas" />
    <input type="button" value="登录" onclick="yz()" />
    </form>
  </body>
</html>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 <%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
    <%
        String uname=request.getParameter("uname");
        String pas=request.getParameter("pas");
        if(uname.equals(pas)){
            session.setAttribute("uname", uname);
            request.getRequestDispatcher("session.jsp").forward(request, response);
        }
        else{
            response.sendRedirect("no.jsp");
        }
     %>
  </body>
</html>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 <%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
  <%
     
    session.invalidate();
    response.setHeader("refresh", "5;url=login.jsp");
     
     %>
    退出成功!
     
  </body>
</html>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 <%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
   <%
   
  String uname=(String)session.getAttribute("uname");
  //如果他是空,说明没登陆,直接访问该页面了
  if(uname==null)
    response.sendRedirect("login.jsp");
   
   %>
  
  欢迎你<%=uname %>
  <a href="loginout.jsp">退出登录</a>
   
  </body>
</html>

 

 

  

 

posted @ 2022-07-01 17:53  刘泰麟  阅读(35)  评论(0编辑  收藏  举报