谁能写个OSCache缓存对象的例子啊,网上搜的大多是缓存页面的,请教高手啊
解决方案 »
- could not find the main class,program will exit
- 列表排序问题
- 有劳高手指点,webwork项目中,JSP页面fmt格式下el表达式显示的设置问题
- POI, excel, template里面table的重用
- 请教: jsp连接sql server 2000 出现的问题(先谢谢了)
- 无法把购物车中的内容显示出来,高手帮我看一下,谢谢!
- 使用可是化的JavaBean做出的页面,在客户端是否需要浏览器的plugin的支持?
- 使用template的疑惑????
- ASP中 Javascript的不算大的小问题?
- JSP求学贴
- 关于获得RequestDispatcher的两种方式
- csdn的资源下载功能好象不能用了
楼主【gs_bg】截止到2008-07-27 21:29:29的历史汇总数据(不包括此帖):
发帖的总数量:21 发帖的总分数:610 每贴平均分数:29
回帖的总数量:16 得分贴总数量:2 回帖的得分率:12%
结贴的总数量:21 结贴的总分数:610
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!
如:
public class DisplayChart extends HttpServlet { /**
* Default constructor.
*/
public DisplayChart() {
super();
} public void init() throws ServletException {
return;
} public static GeneralCacheAdministrator cacheAdmin = new GeneralCacheAdministrator(); public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String path = getServletContext().getRealPath("/");
File file = null;
SimpleDateFormat sdf = new SimpleDateFormat("hh-mm-ss");
try {
file = (File) cacheAdmin.getFromCache(sdf.format(new Date()));
System.out.println("来自缓存!" + sdf.format(new Date()));
} catch (NeedsRefreshException e) {
file = new File(path + "xmls\\Pipe11.xml");
cacheAdmin.putInCache(sdf.format(new Date()), file);
System.out.println("--缓存没有!" + sdf.format(new Date()));
}
sendResponse(file, response);
return;
} /**
* 把文件用响应流写出
* @param file
* @param response
* @throws IOException
*/
public void sendResponse(File file, HttpServletResponse response)
throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
file));
BufferedOutputStream bos = new BufferedOutputStream(response
.getOutputStream());
byte[] input = new byte[1024];
boolean eof = false;
while (!eof) {
int length = bis.read(input);
if (length == -1) {
eof = true;
} else {
bos.write(input, 0, length);
}
}
bos.flush();
bis.close();
bos.close();
}}
public static GeneralCacheAdministrator admin = null; public static GeneralCacheAdministrator getGeneralCacheAdministrator() {
if (admin == null) {
admin = new GeneralCacheAdministrator();
}
return admin;
}
public class NewsAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Vector newses1 = null;
GeneralCacheAdministrator admin = Util.getGeneralCacheAdministrator();
try {
newses1 = (Vector) admin.getFromCache("news",1800); } catch (NeedsRefreshException nre) { News01EntityDAO dao1 = new News01EntityDAO();
String condition = "select * from (select * from NEWS01 where isShow=1 and datetime is not null order by datetime desc )where rownum<=18";
newses1 = dao1.getNewssiteSql(condition);
try {
admin.putInCache("news", newses1); } catch (Exception ex) {
admin.cancelUpdate("news");
ex.printStackTrace();
}
}
request.setAttribute("news", newses1);
return mapping.findForward("news");
}
}