页面跳转之session
题意:设主页为index.jsp 通过session将index.jsp中的信息传送给结果页面result.jsp。(其实,session的生命周期是整个服务器开启过程,具体不做详细介绍)。这个 其实 挺简单的,就几行代码的事情。希望能帮助迷茫着的人。(感觉自己走出了迷茫了,嘿嘿)。
第一步:写index.jsp页面。设置好要传值的name。
<%@ 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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body> <form method = "post" action = "login">
用户名:<input type = "text" name = "name" >
密码:<input type = "password" name = "password">
<input type ="submit" value = "提交">
</form>
</body>
</html>
第二部:strut2.xml配置(action配置)在src目录下面创建(这样才能被服务器找到)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="WEB-INF" extends="struts-default">
<action name="login" class="com.session.test.Login">
<result name="success">Result.jsp</result>
</action>
</package>
</struts>
第三部(两种方法)
3.1.1编写Login类,用session方法获取name值,用于整个服务器开启周期内。
package com.session.test; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class login extends ActionSupport{
private String name;
private String password; public String execute() throws Exception {
ActionContext context=ActionContext.getContext();
context.getSession().put("user",name);
context.getSession().put("password",password);
return SUCCESS;
}
}
3.1.2再编写result.jsp页面。用String name = (String) session.getAttribute("name");获取
<%@ 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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String name = (String) session.getAttribute("name");
String password = (String) session.getAttribute("password");
%>
用户名:<%= name %>
密码:<%= password %>
</body>
</html>
3.2.1
不用配置strut2.xml文件,直接从页面中获取值。为了更好的体现,设置了一个中间页面,midContinue.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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String name = request.getParameter("name");
session.setAttribute("name",name);
String password = request.getParameter("password");
session.setAttribute("password",password);
%>
<a href="Result.jsp">继续</a>
</body>
</html>
3.1.3用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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body> <%
String name = (String) session.getAttribute("name");
String password = (String) session.getAttribute("password");
%>
用户名:<%= name %>
密码:<%= password %>
</body>
</html>
好了这是整个过程,两种方式,希望能帮助需要的人,也不枉我又是敲代码,又是自己敲字。
收工!有问题请回复,这是我自己写的第一篇,期望提些意见。
页面跳转之session的更多相关文章
- Js 的常用方法:页面跳转,Session,类继承
MyApp.Base = function () { } var basePrototype = MyApp.Base["prototype"]; //对象克隆方法 basePro ...
- aspx在页面跳转(Response.Redirect)时丢失session问题及解决办法
[问题描述] 假设a.aspx.cs页面保存有Session["empid"]="3",当a.aspx.cs通过Response.Redirect(" ...
- 爱上MVC~ajax调用分部视图session超时页面跳转问题
回到目录 这个问题出现了很多年了,都没有解决,问题是这样的,有一个需要授权才可以访问的分部视图,在一个view中使用ajax的方法去调用它,然后更新页面的局部DIV,这时,如果你长时间不操作,sess ...
- 关于使用struts2时子窗体页面跳转后在父窗体打开的问题以及Session过期后的页面跳转问题
问题1:传统的系统界面,iframe了三个页面,上,左,右,用户点击注销的按钮在上面得top.jsp里面,方法:<a href="../adminAction/admin_logout ...
- Asp.net页面跳转Session丢失问题
原本去年在做项目时,写好的一记篇博客分享给大家. Asp.net页面跳转Session丢失问题 编写人:CC阿爸 2014-4-2 l 近来在做泛微OA与公司自行开发的系统集成登录的问题.在使用 ...
- Shiro中session超时页面跳转的处理
问题描述 shiro在管理session后,在session超时会进行跳转,这里有两种情况需要考虑,一种是ajax方式的请求超时,一种页面跳转请求的超时. 本文从这两个方面分别考虑并处理. ajax请 ...
- session超时设置+超时页面跳转
session超时设置,方法有三种: (1)在主页面或者公共页面中加入:session.setMaxInactiveInterval(600);参数600单位是秒,即在没有10分钟活动后,sessio ...
- 关于页面跳转之后获取不到session数据的问题
暂时的解决方法有两种,亲测有效: 方法一: 将页面跳转方式由a标签改为请求转发request.getRequestDispatcher("stu_list.jsp").forwa ...
- iframe中请求页面而session失效时页面跳转问题
iframe中请求页面而session失效时页面跳转问题 分类: Web2009-12-11 15:01 656人阅读 评论(0) 收藏 举报 sessioniframejsp 有时候做了就忘了,我记 ...
随机推荐
- Python——爬取人口迁徙数据(以腾讯迁徙为例)
说明: 1.迁徙量是腾讯修改后的数值,无法确认真实性. 2.代码运行期间,腾讯迁徙未设置IP屏蔽和浏览器检测,因此下段代码仅能保证发布近期有效. 3.代码功能:爬取指定一天的四十(此四十是根据自己的城 ...
- Flask 之东方不败一
1,flask的初始 flask是Python的一个轻量级的web框架,相当于django而言. 知识点Python 三大主流web框架的对比 1.Django 主要特点是大而全,集成了很多组件,例如 ...
- raw_input与input
raw_input 不管用户输入的是什么,最后打印的类型都会是str字符串类型 input 会根据用户的输入变换成相应的类型,但是需要注意的是我们用户在输入字符或者字符串的时候,需要给他们加上双引号, ...
- TensorFlow在Windows上的CPU版本和GPU版本的安装指南(亲测有效)
安装说明 平台:Window.Ubuntu.Mac等操作系统 版本:支持GPU版本和CPU版本 安装方式:pip方式.Anaconda方式 attention: 在Windows上目前支持python ...
- 生成唯一UUID
目前有多种方式生成的UUID,根据算法,可确定是否唯一,使用IP和MAC自定义生成唯一主键较妥: // 获取MAC地址的方法 private static String getMACAddress(I ...
- 小E浅谈丨区块链治理真的是一个设计问题吗?
在2018年6月28日Zcon0论坛上,“区块链治理”这个话题掀起了大神们对未来区块链治理和区块链发展的一系列的畅想. (从左至右,分别为:Valkenburgh,Zooko,Jill, Vitali ...
- tar解压指定文件
import tarfileimport sys#tar = tarfile.open('/opt/platform-omp/omp.tar.gz','r')tar = tarfile.open(r' ...
- 【原创】大叔经验分享(49)hue访问hdfs报错/hue访问oozie editor页面卡住
hue中使用hue用户(hue admin)访问hdfs报错: Cannot access: /. Note: you are a Hue admin but not a HDFS superuser ...
- MAC本apache+php配置虚拟域名时踩的坑
昨天在调试Mac自带的Apache+PHP配置域名时,调试的让我怀疑人生.顿时心里一万个草泥马,我就是配置个虚拟域名啊,这么让我受伤 . 1 首先检查一下Apache是否开启, qutao@bogon ...
- SQLAlchemy+Flask-RESTful使用(二)
前言 本来没想到能这么快出二的,谁知道序列化组件写上头了.分享知识真的会上瘾.... 变更记录 # 19.3.18 起笔 # 19.3.18 使用SQLAlchemy排序方法 # 19.3.18 补充 ...