SessionTest

王朝网络·java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

这是我第一次自学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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有