userBean-作用范围session

package com.java1234.model;

public class Student {

private String name;
private int age;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}


}

 <!----数据设置页面-->

<%@ 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>Insert title here</title>
</head>
<body>
<jsp:useBean id="student" scope="session" class="com.java1234.model.Student"/>
<jsp:setProperty property="name" name="student" value="王八蛋"/>
<jsp:setProperty property="age" name="student" value="12"/>
<h1>Session数据设置完毕!</h1>
</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>Insert title here</title>
</head>
<body>
<h1>Application中取值</h1>
<jsp:useBean id="student" scope="application" class="com.java1234.model.Student"/>
<h1>姓名:<jsp:getProperty property="name" name="student"/></h1>
<h1>年龄:<jsp:getProperty property="age" name="student"/></h1>
</body>
</html>

posted @ 2017-02-22 06:34  小拽A  阅读(301)  评论(0编辑  收藏  举报