java中session和application的用法


Session的用法

首先创建2个jsp文件t1.jsp  t2.jsp

在t1.jsp

<%

//设置session的键与值

session.setAttribute("abc", 0);

%>

在t2.jsp中

用EL表达式获取session的值(注意:EL表达式只用于3.0以上的版本)

${abc}

 

(3.0以下的版本就要用)

int i = (Integer)session.getAttribute("abc");

out.println("i的值:"+i);

 

 

application的用法是和session一样的,它们的差异在之前已经发出来了

t1.jsp中

<%

application.setAttribute("abc", 0);

%>

 

t2.jsp

<%

int i = (Integer)application.getAttribute("abc");

i++;

application.setAttribute("abc", i);

%>

${abc}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM