jsp登录会话的简单实现%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%!DOCTYPE html PU...
jsp登录会话的简单实现
<%@ 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>登录界面</title>
</head>
<body>
<form action="test_session2.jsp" method="post">
<table width="300" height="300" border="0" align="center">
<tr height="80" align="center">
<td colspan="2"><font size="24">OO登录</font></td></tr>
<tr height="30">
<td width="80" align="right">用户名:</td>
<td><input type="text" name="name"></td></tr>
<tr height="30">
<td width="80" align="right"> 密码:</td>
<td> <input type="password" name="password"></td></tr>
<tr><td height="40" align="center" colspan="2">
<input type="submit" value="登录"></td></tr>
</table>
</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>登录成功</title>
</head>
<body>
<%
String name = new String( request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
session.setAttribute("name", name);
out.println(name + "成功登陆");
%>
<a href="test_session3.jsp"><br>跳转</a>
</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>会话</title>
</head>
<body>
<%
String str = "";
Object obj = session.getAttribute("name");
if(obj != null){
str = obj.toString();
out.println(str + "已经成功登陆");
}else{
out.println("会话超时,请重新登录。");
}
%>
</body>
</html>
以上就是小编为大家带来的jsp登录会话的简单实现全部内容了,希望大家多多支持~
沃梦达教程
本文标题为:jsp登录会话的简单实现
基础教程推荐
猜你喜欢
- JDK数组阻塞队列源码深入分析总结 2023-04-18
- Java实现线程插队的示例代码 2022-09-03
- Java数据结构之对象比较详解 2023-03-07
- springboot自定义starter方法及注解实例 2023-03-31
- Java实现查找文件和替换文件内容 2023-04-06
- Java文件管理操作的知识点整理 2023-05-19
- ConditionalOnProperty配置swagger不生效问题及解决 2023-01-02
- java基础知识之FileInputStream流的使用 2023-08-11
- java实现多人聊天系统 2023-05-19
- Java并发编程进阶之线程控制篇 2023-03-07