📄 index.jsp
字号:
<%@ page import="java.util.*,java.io.*,shopcart.servlets.*"%><% String uri = request.getRequestURI(); String realPath; int ind; /** * Seconds between checks for updating available * products. Default is 0. */ updateInterval = 60; //Fixes a problem with getRealPath, this should just use the uri but //the beta server returns the context twice so /chapter33/books would be ...\chapter33\chapter33\books //this fixes that by removing the \chapter33\ from the uri realPath = request.getRealPath(uri.substring(uri.indexOf("/",1))); if(needsInit(realPath)) { initProducts(realPath); } //Clean off the file name from the requestURI ind = uri.lastIndexOf("/"); if(ind != (uri.length()-1)) { uri = uri.substring(0,ind); }%><HTML><HEAD><TITLE><%=category%> 4Sale OnLine</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#FF0000" VLINK="#800080"><CENTER><TABLE WIDTH=500 BORDER=0><TR><TD><CENTER><jsp:include page="/AdLinkRotatorServlet"></jsp:include><BR><H3>Welcome to Steve and Scott's<H3><H1><%=category%> 4Sale OnLine</H1><HR></CENTER>Please choose a product to learn more about it.<UL><% int i,max; max = products.size(); for(i=0;i<max;i++) {%> <LI> <A HREF="<%=uri+"/"+products.elementAt(i)%>"> <%=titles.elementAt(i)%> </A> <BR><% }%></UL></TD></TR></TABLE></CENTER></BODY></HTML><%! protected Vector products; protected Vector titles; protected String docRoot; protected shopcart.servlets.WebPageFileFilter filter; protected String category; protected long lastInitTime; protected long updateInterval; public boolean needsInit(String rt) { File dir; boolean retVal = false; long now = System.currentTimeMillis(); if((lastInitTime==0) ||(products == null)) { retVal = true; } else if((now-lastInitTime)>(updateInterval*1000)) { dir = new File(rt); //path may may be a file if(!dir.isDirectory()) dir = new File(dir.getParent()); try { retVal = checkInitForDir(dir,products.size()); } catch(Exception exp) { retVal = true; } } return retVal; } protected boolean checkInitForDir(File dir,int expected) { String[] list; File curFile; int i,max; boolean retVal = false; list = dir.list(filter); max = list.length; //Return true if different number of files if(max != expected) return true; for(i=0;i<max;i++) { curFile = new File(dir,list[i]); if(curFile.lastModified()>lastInitTime) { retVal = true; break; } } return retVal; } public void initProducts(String rt) { File rootDir=null; String[] files; int i,max; File curFile; docRoot = rt; if(products == null) filter = new shopcart.servlets.WebPageFileFilter(); if(products == null) products = new Vector(); else products.removeAllElements(); if(titles == null) titles = new Vector(); else titles.removeAllElements(); try { rootDir = new File(docRoot); if(!rootDir.isDirectory()) rootDir = new File(rootDir.getParent()); if((rootDir!=null) && rootDir.exists()) { category = rootDir.getName(); files = rootDir.list(filter); max = files.length; for(i=0;i<max;i++) { products.addElement(files[i]); curFile = new File(rootDir,files[i]); titles.addElement(titleForFile(curFile)); } } } catch(Exception exp) { products.removeAllElements(); } lastInitTime = System.currentTimeMillis(); } protected String titleForFile(File file) { FileReader fileIn; LineNumberReader lineIn; String retVal = null; char cur; StringBuffer curString = new StringBuffer(); StringBuffer titleString = new StringBuffer(); boolean inTag=false; boolean gotTitle=false; if(file==null) return ""; try { fileIn = new FileReader(file); lineIn = new LineNumberReader(fileIn); cur = (char)lineIn.read(); while(cur != -1) { if(cur == '<') { inTag = true; curString.setLength(0); } else if(cur == '>') { if(curString.toString().equalsIgnoreCase("title")) { gotTitle = true; } else if(curString.toString().equalsIgnoreCase("/title")) { retVal = titleString.toString(); break; } inTag = false; curString.setLength(0); } else if(gotTitle && !inTag) { titleString.append(cur); } else { curString.append(cur); } cur = (char) lineIn.read(); } lineIn.close(); fileIn.close(); } catch(Exception exp) { retVal = null; } if("".equals(retVal) || (retVal == null)) retVal = file.getName(); return retVal; }%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -