SessionTest

这是我第一次自学JSP 内部对象Session 的例子:
F:/Tomcat 5.0/webapps/ROOT/session
main.htm
session1.jsp
session2.jsp

1。main.htm

<html>
<head><title>session 应用1</title></head>
<body>
<form method=post action="session1.jsp">
请输入出版社名称:
<input type=text name="yourname">
<input type=submit value="确定">
<input type=reset value="重来">
</form>
</body>
</html>


2。session1.jsp

<%--测试application 对象--%>
<%
application.setAttribute("app","你好,application");
%>

<html>
<head><title>session 应用2</title></head>
<body>

<%--测试session 对象--%>
<%
String name1 = request.getParameter("yourname");
session.putValue("username",name1);
%>
出版社的名称是:<%= name1 %>
<p>

<form method=post action = "session2.jsp">
最近新出版的书是什么?
<input type=text  name="book">
<p>
<input type=submit value="确定">
<input type=reset value="重来">
</form>

</body>
</html>


3。session2.jsp

<html>
<head><title>session 应用3</title></head>
<body>

<%! String book = "";%>

<!--测试session对象和application 对象-->
<%
String book = request.getParameter("book");
String name2 =(String) session.getValue("username");

String appname = (String) application.getAttribute("app");
%>

出版社的名称是:<%= name2 %>
<p>
最近新出版的书是:<%= book %>
<p>
Application 对象赋值String 测试:<%= appname %>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值