1.WEB-INF 目录的文件外界不能直接访问,因此可以通过把一些后台的jsp文件放在WEB-INF 文件夹中以提高安全性.
同时可以通过程序配置去访问这些页面,在 web.xml中作出一定的配置即可.
页面部分
2.关于 session 的部分
3.关于 response
同时可以通过程序配置去访问这些页面,在 web.xml中作出一定的配置即可.
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.4"
- xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <servlet-name>back</servlet-name>
- <!-- 注意此处的配置不是 servlet-class,也就是说 当用户请求 /back,将访问的是 WEB-INF下面的 back.jsp-->
- <jsp-file>/WEB-INF/back.jsp</jsp-file>
- <!-- 同时还可以配置相应的初始化变量值 -->
- <init-param>
- <param-name>username</param-name>
- <param-value>Simon lv</param-value>
- </init-param>
- <init-param>
- <param-name>password</param-name>
- <param-value>888888</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>back</servlet-name>
- <url-pattern>/back</url-pattern>
- </servlet-mapping>
- </web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>back</servlet-name>
<!-- 注意此处的配置不是 servlet-class,也就是说 当用户请求 /back,将访问的是 WEB-INF下面的 back.jsp-->
<jsp-file>/WEB-INF/back.jsp</jsp-file>
<!-- 同时还可以配置相应的初始化变量值 -->
<init-param>
<param-name>username</param-name>
<param-value>Simon lv</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>888888</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>back</servlet-name>
<url-pattern>/back</url-pattern>
</servlet-mapping>
</web-app>
页面部分
- <body>
- <h1>Back Page in WEB-INF</h1>
- <%
- //可以通过 config 内置对象获取配置在 web.xml中的值
- String user = config.getInitParameter("username");
- String password = config.getInitParameter("password");
- %>
- <h1>User Name:<%=user %></h1>
- <h1>User Password:<%=password %></h1>
- </body>
<body>
<h1>Back Page in WEB-INF</h1>
<%
//可以通过 config 内置对象获取配置在 web.xml中的值
String user = config.getInitParameter("username");
String password = config.getInitParameter("password");
%>
<h1>User Name:<%=user %></h1>
<h1>User Password:<%=password %></h1>
</body>
2.关于 session 的部分
- <%
- //得到 session id 32位
- out.print("<p>Session ID:"+session.getId());
- //判断 session 是否是新的
- boolean isNew = session.isNew();
- out.print("<p>Session is new :"+isNew);
- //session创建时间
- long createTime = session.getCreationTime();
- out.print("<p>Session CreateTime:"+new Date(createTime));
- //session 用户最后的操作时间
- long lastTime = session.getLastAccessedTime();
- out.print("<p>Last time:"+new Date(lastTime));
- //session 最大非间隔活动时间
- out.print("<p>Max Inactive Time:"+session.getMaxInactiveInterval());
- %>
<%
//得到 session id 32位
out.print("<p>Session ID:"+session.getId());
//判断 session 是否是新的
boolean isNew = session.isNew();
out.print("<p>Session is new :"+isNew);
//session创建时间
long createTime = session.getCreationTime();
out.print("<p>Session CreateTime:"+new Date(createTime));
//session 用户最后的操作时间
long lastTime = session.getLastAccessedTime();
out.print("<p>Last time:"+new Date(lastTime));
//session 最大非间隔活动时间
out.print("<p>Max Inactive Time:"+session.getMaxInactiveInterval());
%>
3.关于 response
- response.setHeader();可以用来设置头信息
- response.setHeader("refresh","1");//1秒钟刷新一次
- response.setHeader("refresh","3;url=跳转的URL地址");//3秒钟后自动跳转
原文出自:http://lvp.iteye.com/blog/627760