网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

直接测试oscache的webApp

http://www.diybl.com/ 2008-2-29  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

日期:2008-02-26
首先下载oscache的包:目前是 https://oscache.dev.java.net/files/documents/629/61427/oscache-2.4.1-full.zip
解压其中有一个webapp的目录就是oscache自带的例子。
1.在eclipse新建一个web project 名字随便:Test
2.将webApp内容拷贝到webRoot下
3.在WEB-INF目录下新建一个lib目录,将oscache-2.4.1.jar放到里面
4.将classes 下的目录拷贝到src目录下
5.在解压缩的文件中找到oscache.tld拷贝到src目录下
6.修改web.xml,增加
<taglib>
 <taglib-uri>http://www.opensymphony.com/oscache</taglib-uri>
 <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
</taglib>
7.发布就可以了,访问http://localhost:8080/Test  看看效果。
看了一下例子就很容易的明白,cache标签的用法了。
还有一个很重要的例子他没有就是 key为空,如果key为空则默认为当前url,这个可以缓存同一个jsp,不同参数下的情况。
这个对与论坛或者分类的网页很有帮助。
代码如下:
<%@ page import="java.util.*" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>

<%
String scope = "application";
if (request.getParameter("scope") != null)
{
 scope = request.getParameter("scope");
}
%>
<head>
<title>Test Page</title>
<style type="text/css">
body {font-family: Arial, Verdana, Geneva, Helvetica, sans-serif}
</style>
</head>
<body>

<a href="<%= request.getContextPath() %>/">Back to index</a><p>

<a href="cachetesturl.jsp?url=1">url=1</a>
<a href="cachetesturl.jsp?url=2">url=2</a>
<br/>
<% Date start = new Date(); %> <b>Start Time</b>: <%= start %><p>
<hr>
 <%-- Note that we have to supply a cache key otherwise the ''refresh'' parameter
         causes the refreshed page to end up with a different cache key! --%>
<cache:cache
 scope="application">
 <b>Cache Time</b>: <%= new Date() %><br>
</cache:cache>
<hr>
<b>End Time</b>: <%= new Date() %><p>

<b>Running Time</b>: <%= (new Date()).getTime() - start.getTime() %> ms.<p>
</body>
当同一个jsp情况下,url不同时,缓存不同的内容。 



文章整理:DIY部落 http://www.diybl.com (本站)   【点击打包该文章】
如果图片或页面不能正常显示请点击这里 站内搜索:   
上一篇文章:关于JBoss运行ejb
下一篇文章:Log4j–浅谈

文章评论

请您留言

 

最新新闻