页面跳转之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 有时候做了就忘了,我记 ...
随机推荐
- [Android] Android 手机下 仿 今日头条 新闻客户端
利用一个月的时间,自学了 Android 开发 ,为了检验学习成果,特意 开发了这个 仿 今日头条 新闻客户端 AppNews 包括图文新闻+视频新闻+图片新闻 预览演示如下: 功能说明: 1)底部 ...
- VMware 安装虚拟机系统
Ø 简介 本文主要介绍使用 VMware 安装虚拟机系统. 1. 创建虚拟机 1) 打开VMware,创建新虚拟机 2) 选择需要安装系统的iso镜像文件 3) 选择需要安装的Win ...
- awk删除重复文件
#!/bin/bash #查找并删除重复文件,每个文件只保留1份 ls -LS --time-style=long-iso | awk 'BEGIN { getline; getline; name1 ...
- python flsak 框架
1.flask 轻量级微型web框架 优点:微框架.简单.可扩展 将flask变量实例化到app变量中 如果想要flask自动加载修改后的代码,要app.run(debug=True) 2.路由和视 ...
- Emit 自动生成IL代码,注入代码
Spring 框架中的注入代码,以及自动生成对接口的实现,则根据il代码注入 Emit学习(1)-Emit概览 一.Emit概述 Emit,可以称为发出或者产生.在Framework中,与Emit相关 ...
- 如何识别Studio 5000程序开发版本号
前言:中.大型AB PLC的编程软件从以前的RSLogix 5000到目前的Studio 5000,都是有版本号的,如RSLogix 5000 V19.0.Studio 5000 V32.高版本的软件 ...
- further configuration avilable 不见了
Dynameic Web Module的further configuration avilable 不见了 打开目录下的 org.eclipse.wst.common.project.facet. ...
- js原型杂谈
1.通俗点讲原型对象就是内存中为其他对象提供共享属性和方法的对象. 2.所有原型对象都具备一个constructor属性,这个属性是一个指向包含prototype属性函数的一个指针(敢不敢再绕点!). ...
- SimpleDateFormat日期格式解析
先看一个代码示例: import java.text.SimpleDateFormat; import java.util.Date; public class test{ public static ...
- 【干货】提取图片元数据之exiftool
知识源:UC3Mx: INF.2x网络安全基础:实践方法 课程 第1周.讲座2.计算机取证 常见的法医痕迹 2.2.1.元数据 exiftool是一种查看,更新或删除元数据的工具.是Window ...