JSP基础——内置对象(2)

最近在学习慕课网的课程《Java遇见HTML——JSP篇》,简单做些记录。

课程网址为:http://www.imooc.com/learn/166

六、 Session对象

 

 

 

 

 

七 application对象

 

代码:

 

[html] view plain copy
 
  1. <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'application.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.   
  23.   </head>  
  24.     
  25.   <body>  
  26.     <h1>application对象</h1>  
  27.     <%  
  28.         application.setAttribute("city", "北京");  
  29.         application.setAttribute("postcode", "10000");  
  30.         application.setAttribute("email", "lisi@162.com");  
  31.     %>  
  32.     application中的属性有:<%  
  33.         Enumeration attributes = application.getAttributeNames();  
  34.         while(attributes.hasMoreElements()){  
  35.             out.println(attributes.nextElement() + "  ");  
  36.         }  
  37.     %><br>  
  38.     JSP(SERVLET)引擎名及版本号:<%=application.getServerInfo() %><br>  
  39.   </body>  
  40. </html>  

 

 

八、 其他

 

 

 

posted on 2017-06-21 14:14  alex5211314  阅读(114)  评论(0编辑  收藏  举报

导航