jsp session练习简单的登录

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="lianxi6.jsp" method="post">
账号:<input type="text" name="name">
<br>
密码:<input type="password" name="password" > 
<br>
<input type="submit" value="登录">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 
String name=new String (request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
session.setAttribute("name", name);
String password=new String (request.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
session.setAttribute("password", password);
%>
登陆成功
<%
response.setHeader("refresh", "5;URL=lianxi7.jsp");
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 
String name=session.getAttribute("name").toString();
String password=session.getAttribute("password").toString();
out.print("账号:"+name);
out.print("<br>密码:"+password);
%>
</body>
</html>

posted on 2016-06-28 09:28  煜渝  阅读(256)  评论(0编辑  收藏  举报

导航