JSP中application用法

<%@ page contentType="text/html" pageEncoding="gbk"%>
<%@ page import="java.util.*"%>
<html>
<title>application</title>
<body>
<%
application.setAttribute("name","李華");
application.setAttribute("age",new Date());
%>
 
<a href="application1.jsp">通過超鏈接取得屬性</a>
</body>

</html>


以下是application1.jsp的內容

<%@ page contentType="text/html" pageEncoding="gbk"%>
<%@ page import="java.util.*"%>
<html>
<title>application</title>
<%
String username=(String)application.getAttribute("name");
Date age = (Date)application.getAttribute("age");
%>
<h2><%=username %></h2>
<h2><%=age %></h2>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章