JSP例子等:三元運(yùn)算符,JSP四大作用域,EL表達(dá)式,$,頁面跳轉(zhuǎn),轉(zhuǎn)發(fā)【詩書畫唱】
1、創(chuàng)建一個(gè)Student對(duì)象,里面包含有姓名sname(String),愛好hobby(String),生日birth(Date),性別ssex(char),班級(jí)scls(String)五個(gè)屬性,在stu.jsp頁面通過EL表達(dá)式將學(xué)生的詳細(xì)信息顯示頁面上

package com.SSHC;
import java.util.Date;
public class Student {
private String sname;
private String hobby;
private Date birth;
private char ssex;
private String scls;
public Student(){
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public char getSsex() {
return ssex;
}
public void setSsex(char ssex) {
this.ssex = ssex;
}
public String getScls() {
return scls;
}
public void setScls(String scls) {
this.scls = scls;
}
public Student(String sname, String hobby, Date birth, char ssex, String scls) {
super();
this.sname = sname;
this.hobby = hobby;
this.birth = birth;
this.ssex = ssex;
this.scls = scls;
}
@Override
public String toString() {
return "Student [sname=" + sname + ", hobby=" + hobby + ", birth=" + birth
+ ", ssex=" + ssex + ", scls=" + scls + "]";
}
}


<%@page import="com.SSHC.Student"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
?
? ? Student S = new Student();
? ? S.setSname("詩書畫唱");
? ? S.setHobby("做視頻和編程");
? ??
? ?//下面的Date的類型要聲明為“X/X/X”的格式,不然會(huì)報(bào)錯(cuò)等。
? ? Date? D= new Date("2000/7/20");
? ? S.setBirth(D);
? ??
??
? ? S.setSsex('男');
? ? S.setScls("詩書畫唱班");
?
? ??
? ? request.setAttribute("KeyS", S);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ?
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,姓名:${KeyS.sname }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性,愛好:${KeyS["hobby"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,生日:${KeyS.birth }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性,性別:${KeyS["ssex"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,班級(jí):${KeyS.scls }</h1>??
? ? </body>
</html>


2、創(chuàng)建Car汽車類,包含品牌,價(jià)格屬性,通過a.jsp頁面跳轉(zhuǎn)到b.jsp頁面,在a.jsp頁面創(chuàng)建Car對(duì)象,在b.jsp頁面通過EL表達(dá)式打印出汽車的品牌和價(jià)格。

package com.SSHC;
public class Car {
private? String pinPai;
private? Double? price;
public String getPinPai() {
return pinPai;
}
public void setPinPai(String pinPai) {
this.pinPai = pinPai;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}




<%@page import="com.SSHC.Student"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
?
? ? Student S = new Student();
? ? S.setSname("詩書畫唱");
? ? S.setHobby("做視頻和編程");
? ??
? ?//下面的Date的類型要聲明為“X/X/X”的格式,不然會(huì)報(bào)錯(cuò)等。
? ? Date? D= new Date("2000/7/20");
? ? S.setBirth(D);
? ??
??
? ? S.setSsex('男');
? ? S.setScls("詩書畫唱班");
?
? ??
? ? request.setAttribute("KeyS", S);
? ? request.getRequestDispatcher("b.jsp")
? ? .forward(request, response);
? ??
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ?
? ? </body>
</html>




3、創(chuàng)建一個(gè)Product商品類,包含商品名稱、商品價(jià)格,商品類型,通過my.jsp跳轉(zhuǎn)到y(tǒng)ou.jsp頁面,在my.jsp頁面創(chuàng)建一個(gè)商品類,在you.jsp頁面通過EL表達(dá)式顯示出商品的所有信息。

package com.SSHC;
public class Product {
? ? private String name;
? ? private Double price;
? ? private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}


<%@page import="com.SSHC.Product"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
?
? ? Product S = new Product();
? ? S.setName("詩書畫唱");
? ? S.setPrice(2.33);
? ??
?
? ? S.setType("CD類");
?
? ??
? ? request.setAttribute("KeyS", S);
? ? request.getRequestDispatcher("you.jsp")
? ? .forward(request, response);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ?
? ? </body>
</html>


<%@ page language="java" contentType="text/html; charset=utf-8"
? ? pageEncoding="utf-8"%>? ?
? ? <%request.getAttribute("KeyS"); %>
<!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>
? <h1>用“.”調(diào)用的方法調(diào)用屬性,商品名稱:${KeyS.name }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性,商品價(jià)格:${KeyS["price"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,商品類型:${KeyS.type }</h1>
? ? ?
</body>
</html>


4、(難)實(shí)現(xiàn)頁面跳轉(zhuǎn)show.jsp跳轉(zhuǎn)到result.jsp,根據(jù)show.jsp頁面的prop值動(dòng)態(tài)顯示第1題中Student對(duì)象的屬性值。
例如在show.jsp頁面中,request.setAttribute("prop","sname");
在跳轉(zhuǎn)到result.jsp頁面后,顯示學(xué)生的姓名值(提示:使用[]方式動(dòng)態(tài)顯示)


package com.SSHC;
import java.util.Date;
public class Student {
private String sname;
private String hobby;
private Date birth;
private char ssex;
private String scls;
public Student(){
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public char getSsex() {
return ssex;
}
public void setSsex(char ssex) {
this.ssex = ssex;
}
public String getScls() {
return scls;
}
public void setScls(String scls) {
this.scls = scls;
}
public Student(String sname, String hobby,?
Date birth, char ssex, String scls) {
super();
this.sname = sname;
this.hobby = hobby;
this.birth = birth;
this.ssex = ssex;
this.scls = scls;
}
@Override
public String toString() {
return "Student [sname=" + sname +?
", hobby=" + hobby + ", birth=" + birth
+ ", ssex=" + ssex + ", scls=" + scls + "]";
}
}


<%@page import="com.SSHC.Student"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
?
? ? Student S = new Student();
? ? S.setSname("詩書畫唱");
? ? S.setHobby("做視頻和編程");
? ??
? ?//下面的Date的類型要聲明為“X/X/X”的格式,不然會(huì)報(bào)錯(cuò)等。
? ? Date? D= new Date("2000/7/20");
? ? S.setBirth(D);
? ??
??
? ? S.setSsex('男');
? ? S.setScls("詩書畫唱班");
?
? ??
? ? request.setAttribute("KeyS", S);
? ? request.getRequestDispatcher("result.jsp")
? ? .forward(request, response);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ?
? ? </body>
</html>


<%@page import="com.SSHC.Product"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
? ? Object obj = request.getAttribute("KeyS");
? ?
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,
? ? ? ? keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
?<h1>用“[]”調(diào)用的方法調(diào)用屬性,姓名:${KeyS["sname"] }</h1>
? ??
? ? </body>
</html>


5、在第1題中,在a.jsp頁面中傳遞一個(gè)message到b.jsp頁面,在b.jsp頁面中通過EL表達(dá)式和三元運(yùn)算符進(jìn)行顯示:如果message的內(nèi)容是success,則顯示登錄成功,否則顯示登錄失敗。

<%@page import="com.SSHC.Student"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
?
? ? Student S = new Student();
? ? S.setSname("詩書畫唱");
? ? S.setHobby("做視頻和編程");
? ??
? ?//下面的Date的類型要聲明為“X/X/X”的格式,不然會(huì)報(bào)錯(cuò)等。
? ? Date? D= new Date("2000/7/20");
? ? S.setBirth(D);
? ??
??
? ? S.setSsex('男');
? ? S.setScls("詩書畫唱班");
?
? ??
? ? request.setAttribute("KeyS", S);
? ??
? ? String message="success";
? ? request.setAttribute("KeyM", message);
? ??
? ? request.getRequestDispatcher("b.jsp")
? ? .forward(request, response);
? ??
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ?
? ? </body>
</html>


<%@ page language="java" contentType="text/html; charset=utf-8"
? ? pageEncoding="utf-8"%>? ?
? ? <%request.getAttribute("KeyS");?
?request.getAttribute("KeyM");%>
<!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>
方法一(用equals判斷相當(dāng)):<br>
${KeyM.equals("success")?"登錄成功":"登錄失敗" }<br>
方法二(用==判斷相當(dāng)):<br>
${KeyM=="success"?"登錄成功":"登錄失敗" }
? <h1>用“.”調(diào)用的方法調(diào)用屬性,姓名:${KeyS.sname }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性,愛好:${KeyS["hobby"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,生日:${KeyS.birth }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性,性別:${KeyS["ssex"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性,班級(jí):${KeyS.scls }</h1>?
</body>
</html>


下面是要學(xué)習(xí)的內(nèi)容,可以當(dāng)作學(xué)習(xí)路線等提前去預(yù)習(xí)等:


自己寫的題目:
用上EL表達(dá)式,三元表達(dá)式,直接調(diào)用,“."或”[]“調(diào)用類的屬性值等
下面是自己寫的答案和超有用得個(gè)人的總結(jié)等:


package com.SSHC;
public class User {
? ? private String act;
? ? private String pwd;
public String getAct() {
return act;
}
public void setAct(String act) {
this.act = act;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}


<%--
下面是用import導(dǎo)入包 --%>
<%@page import="com.SSHC.User"%>
<%@ page language="java" contentType="text/html;?
charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()+path+"/";
? ??
/*
? ? 下面是先聲明一個(gè)num的值為66,之后給num取名字為"_num"。
? ? msg,flag也類似,都用了setAttribute方法。
? ? 只不過
msg,flag的作用域?yàn)閞equest,而
num的作用域?yàn)閍pplication。
application
[??pl??ke??n]
n. 申請(qǐng); 請(qǐng)求;
? ? */
? ? //————————
? ? int num =66;
? ? application.setAttribute("_num", num);
? ? //——————
? ? String msg = "關(guān)注詩書畫唱并給三連!";
? ? request.setAttribute("_msg", msg);
? ? //——————
? ? boolean flag = true;
? ? request.setAttribute("_flag", flag);
? ? //——————
? ??
? ? /*
? ? 下面是聲明了一個(gè)User類,用上
? ? new,就是把User類調(diào)用出來。
? ? 之后用一個(gè)變量接收,
? ? 而要想接收User類的話,就可以通過把
? ? (可統(tǒng)一變的)別名u的數(shù)據(jù)類型
? ? 聲明為User。
? ??
? 之后可以通過用setXXX方法給User的各個(gè)屬性等
? 賦值。最后將u對(duì)象放到作用域 request的
? setAttribute方法中去,命名為"_user",
? 以便同過"_user"使用EL表達(dá)式:
? ? */
? ? User u = new User();
? ? u.setAct("詩書畫唱");
? ? u.setPwd("666");
? ??
? ? request.setAttribute("_user", u);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content=
? ? ? ? "keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ??
? ? <%--
? ? 自己對(duì)EL表達(dá)式的總結(jié):
? ? 先用上XXX.setAttribute("YYY",ZZZ)。
? ? XXX就是request等的作用域。
? ? "YYY"就是別名,類似于Key鍵,
? ? ZZZ類似于Value。
? ? 總之如果ZZZ="Value",那么通過
? ??
? ? ${YYY}在HTML網(wǎng)頁界面調(diào)用的值就是
? ? Value。
? ? 如果直接${YYY},ZZZ沒被賦值,
? ??
? ? 那么在網(wǎng)頁打印的內(nèi)容就是空白,什么都沒有,而不是
? ? Null等內(nèi)容。
? ? ——————
? ? 如果"YYY"為類的別名,
? ??
? ? 那么可以通過${YYY.類的屬性名}
? ? 或${YYY[類的屬性名]}調(diào)用。
? ??
? ? 這些都是JS中的調(diào)用方法。
? ? ——————————
? ??
? ? 下面就是EL表達(dá)式的調(diào)用:
? ??
? ? ?--%>
? ? ? ?<h1>直接調(diào)用:${_num }</h1>
? ? ? ?<h1>直接調(diào)用:${_msg }</h1>
? ? ? ?<!--?
? ? ? ?
? ? ? ?
? ? ?運(yùn)用設(shè)計(jì):??
? ? ? ?如果flag為false就顯示未登錄,如果flag為true,就顯示注銷 。
? ? ? ?
? ? ? ?三元表達(dá)式(也就是三元運(yùn)算符,三目表達(dá)式,
? ? ? ?總之我這些叫法我都聽別人講過。
? ? ? ?
? ? ? ?自己總結(jié)的三元表達(dá)式的語法:
? ? ? ?
? ? ? ?A?B:C(就是A為布爾型,boolean ,已經(jīng)聲明為true或flase
? ? ? 當(dāng) A為true時(shí)顯示B,B起作用。 當(dāng) A為flase時(shí),C起作用。
? ? ? ?)
? ? ? ?
? ? ? ?
? ? ? ?-->
? ? ? ?<h1>用三元表達(dá)式調(diào)用:${_flag ? "注銷" : "未登錄" }</h1>
? ? ? ?<!--?
? ? ? ?
? ? ? ?
? ? ? ?_user.act中的act就是User類中的屬性名
? ? ? ?
? ? ? ?
? ? ? ? -->
? ? ? ??
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性:${_user.act }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性:${_user["act"] }</h1>
? ? ? ?<h1>用“.”調(diào)用的方法調(diào)用屬性:${_user.pwd }</h1>
? ? ? ?<h1>用“[]”調(diào)用的方法調(diào)用屬性:${_user["pwd"] }</h1>
? ? </body>
</html>



______
擴(kuò)展知識(shí):
EL表達(dá)式
EL表達(dá)式就是JSP中的一種特有的語言,可以簡化我們的java代碼。
EL表達(dá)式寫法: ${表達(dá)式},注意: {}中間只能是表達(dá)式,不能是語句。
EL表達(dá)式有兩種運(yùn)算符: . 和[] (JS對(duì)象的運(yùn)算符)
EL表達(dá)式可以寫在JSP頁面的任何地方。
EL表達(dá)式中的變量的顯示過程:會(huì)依次從pageContext, request, session以及
applicaion四個(gè)作用域中找這個(gè)變量, 一旦找到了就返回這個(gè)值,如果四個(gè)作用域都
找不到,就顯示為”" (不是顯示為null)。

application
[??pl??ke??n]
n. 申請(qǐng); 請(qǐng)求;
?__________
JSP四大作用域分別為:
page, request ,session, application 。
?
? ??第一個(gè)作用域是page,他只在當(dāng)前頁面有效,也就是用戶請(qǐng)求的頁面有效,當(dāng)當(dāng)前頁面關(guān)閉或轉(zhuǎn)到其他頁面時(shí),page對(duì)象將在響應(yīng)回饋給客戶端后釋放。
????第二個(gè)作用域是request,他在當(dāng)前請(qǐng)求中有效,request可以通過setAttribute()方法實(shí)現(xiàn)頁面中的信息傳遞,也可以通過forward()方法進(jìn)行頁面間的跳轉(zhuǎn),需要注意的是request是轉(zhuǎn)發(fā)不是重定向,轉(zhuǎn)發(fā)相對(duì)于瀏覽器來說是透明的,也就是無論頁面如何跳轉(zhuǎn),地址欄上顯示的依舊是最初的地址。
????第三個(gè)作用域是session,他在當(dāng)前回話中有效。當(dāng)一個(gè)臺(tái)電腦上的同一瀏覽器對(duì)服務(wù)器進(jìn)行多次訪問時(shí),在這多次訪問之間傳遞的信息就是session作用域的范圍。它從瀏覽器發(fā)出第一個(gè)HTTP請(qǐng)求即可認(rèn)為會(huì)話開始,但是會(huì)話結(jié)束的時(shí)間是不確定的,因?yàn)樵跒g覽器關(guān)閉時(shí)并不會(huì)通知服務(wù)器,一般Tomcat設(shè)置的默認(rèn)時(shí)間為120分鐘,也可以通過setMaxInactiveInterval(int)方法進(jìn)行設(shè)置,或是通過invalidate()方法強(qiáng)制結(jié)束當(dāng)前會(huì)話。
????第四個(gè)作用域是application,他在所有的應(yīng)用程序中都有效,也就是當(dāng)服務(wù)器開始到服務(wù)器結(jié)束這段時(shí)間,application作用域中存儲(chǔ)的數(shù)據(jù)都是有效的,同樣可以通過setAttribute賦值和getAttribute取值。?

