页面跳转之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 有时候做了就忘了,我记 ...
随机推荐
- What is the difference between __str__ and __repr__ in Python
from https://www.pythoncentral.io/what-is-the-difference-between-__str__-and-__repr__-in-python/ 目的 ...
- tomcat配置及环境搭建
步骤一 下载tomcat 下载tomcat并安装,登陆tomcat官网,http://tomcat.apache.org/,Windows系统建议选择Windows Service Installer ...
- Spring.Net 入门学习笔记-----one
一. 基本概念 Spring.Net是一个轻量级的控制反转(Ioc)和面向切面的(Aop)的容器框架: Ioc:控制反转:简单的说就是将创建对象的控制权转交给外部容器(IApplicationC ...
- python 去除html 超链接href 如何实现?
今天持久男 在抓取数据的时候发现很多内容都加了锚文本, 这怎么办呢? 没办法只能通过工具解决 我是这样解决的: 例如: soup = BeautifulSoup('<p>Hello < ...
- word20170105订酒店 hotel reservation有用的词和句子
有用的词: hotel reservation/booking: 酒店预订 standard room:标准间 suite: 套房 king size bed: 大床房 double bed:双床房 ...
- 记事本:一些js案例以及DOM和BOM
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 你循环的时候就可以给他们赋值了,那么就不用addClass,再根据类选择器处理,代码能一气呵成就别写成两段了
function onCopyButtonClick() { $(".index:checked").each(function () { $(] + "__WeekCo ...
- 基于Spring注解搭建SpringMVC项目
在2018寒冬,我下岗了,因为我的左脚先迈进了公司的大门.这不是重点,重点是我扑到了老板小姨子的怀里. 网上好多教程都是基于XML的SpringMVC,想找一篇注解的,但是写的很模糊,我刚好学到这里, ...
- GX/GZOI2019 day2 解题报告
GX/GZOI2019 day2 解题报告 题目链接 逼死强迫症 旅行者 旧词 t1 逼死强迫症 显然地,记 \(f(i)\) 为长度为 \(i\) 的木板的答案,可得: \(\\\) \[f(i)= ...
- HDMI热插拔检测原理
HDMI(19Pin)/DVI(16 pin)的功能是热插拔检测(HPD),这个信号将作为主机系统是否对HDMI/DVI是否发送TMDS信号的依据.HPD是从显示器输出送往计算机主机的一个检测信号.热 ...