userBean-作用范围application

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="application" class="com.java1234.model.Student"/>
<jsp:setProperty property="name" name="student" value="李四"/>
<jsp:setProperty property="age" name="student" value="13"/>
<h1>Application数据设置完毕!</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:47  小拽A  阅读(395)  评论(0编辑  收藏  举报