题意:设主页为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的更多相关文章

  1. Js 的常用方法:页面跳转,Session,类继承

    MyApp.Base = function () { } var basePrototype = MyApp.Base["prototype"]; //对象克隆方法 basePro ...

  2. aspx在页面跳转(Response.Redirect)时丢失session问题及解决办法

    [问题描述] 假设a.aspx.cs页面保存有Session["empid"]="3",当a.aspx.cs通过Response.Redirect(" ...

  3. 爱上MVC~ajax调用分部视图session超时页面跳转问题

    回到目录 这个问题出现了很多年了,都没有解决,问题是这样的,有一个需要授权才可以访问的分部视图,在一个view中使用ajax的方法去调用它,然后更新页面的局部DIV,这时,如果你长时间不操作,sess ...

  4. 关于使用struts2时子窗体页面跳转后在父窗体打开的问题以及Session过期后的页面跳转问题

    问题1:传统的系统界面,iframe了三个页面,上,左,右,用户点击注销的按钮在上面得top.jsp里面,方法:<a href="../adminAction/admin_logout ...

  5. Asp.net页面跳转Session丢失问题

    原本去年在做项目时,写好的一记篇博客分享给大家. Asp.net页面跳转Session丢失问题   编写人:CC阿爸 2014-4-2 l  近来在做泛微OA与公司自行开发的系统集成登录的问题.在使用 ...

  6. Shiro中session超时页面跳转的处理

    问题描述 shiro在管理session后,在session超时会进行跳转,这里有两种情况需要考虑,一种是ajax方式的请求超时,一种页面跳转请求的超时. 本文从这两个方面分别考虑并处理. ajax请 ...

  7. session超时设置+超时页面跳转

    session超时设置,方法有三种: (1)在主页面或者公共页面中加入:session.setMaxInactiveInterval(600);参数600单位是秒,即在没有10分钟活动后,sessio ...

  8. 关于页面跳转之后获取不到session数据的问题

    暂时的解决方法有两种,亲测有效: 方法一:  将页面跳转方式由a标签改为请求转发request.getRequestDispatcher("stu_list.jsp").forwa ...

  9. iframe中请求页面而session失效时页面跳转问题

    iframe中请求页面而session失效时页面跳转问题 分类: Web2009-12-11 15:01 656人阅读 评论(0) 收藏 举报 sessioniframejsp 有时候做了就忘了,我记 ...

随机推荐

  1. [转载]如何在ubuntu上使用github

    来源:https://blog.csdn.net/tina_ttl/article/details/51326684 https://blog.csdn.net/u013551462/article/ ...

  2. 开源顶级持久层框架——mybatis(ibatis)——day01

    mybatis-day01     1.对原生态jdbc程序中的问题总结         1.1环境             java环境:jdk             eclipse:indigo ...

  3. PaginatorSet

    from django.core.paginator import Paginator, EmptyPage class PaginatorSet: def __init__(self, limit= ...

  4. 题解 P3871 【[TJOI2010]中位数】

    orz各位大佬,题解太强了,主席树,堆,线段树,splay,还有暴力,太巨了.所以我用的是fhq treap(好像更高级).算了. 反正都是平衡树,这道题就是动态求中位数,不会做的同学可以先做弱化版P ...

  5. Asp.net Core导出Excel

    本篇文章是在MVC设计模式下,基于windows系统的Excel导出 1.前台的实现不用我多说了吧,加一个a标签链接地址跳到它所调用的方法里面,可以根据当前页面的查询条件去传值,从而查询出你想要的数据 ...

  6. C. Neko does Maths(数论 二进制枚举因数)

     题目链接:https://codeforces.com/contest/1152/problem/C 题目大意:给你a和b,然后让你找到一个k,使得a+k和b+k的lcm. 学习网址:https:/ ...

  7. Balanced Number HDU - 3709

    题目大意:若一个数以某个位置为支点,支点左右的加权和相同,这样的数被称为平衡数,求区间内平衡数的个数 思路:枚举支点位置,针对每个支点进行数位DP,但是0比较特殊,假设该数的长度为len,枚举len次 ...

  8. 「JavaScript面向对象编程指南」对象

    对象的属性名可加上引号,下面三行代码所定义的内容是完全相同的 var hero = { occupation : 1 }; var hero = { "occupation" : ...

  9. 自定义QGraphicsItem

    简述: QGraphicsItem 是场景中 item 的基类.图形视图提供了一些典型形状的标准 item,例如:矩形 ( QGraphicsRectItem ).椭圆 ( QGraphicsElli ...

  10. Python 爬虫-进阶开发之路

    第一篇:爬虫基本原理: HTTP, 爬虫基础 第二篇:环境安装与搭建: 第三篇:网页抓取:urllib,requests,aiohttp , selenium,  appium 第四篇:网页解析:re ...