Title: A Conditional Get Method for JSP
1A Conditional Get Method for JSP
- Stuart Maclean
- Intelligent Transportation Systems
- University of Washington
- http//www.its.washington.edu
2HTTP 1.1 Conditional Get
- GET foo.html
- Status 200 (OK)
- Content-Length N
- Last-Modified T
- GET foo.html
- If-Modified-Since T
- Status 304 (Not Modified)
- Content-Length -
- Last-Modified T
3HttpServlet.service( HttpServletRequest
req,HttpServletResponse resp ) if(
GET.equals( req.getMethod() ) ) long
lastModified getLastModified( req ) if(
lastModified -1 ) doGet( req, resp
) else long ifModSince
req.getDateHeader( If-Modified-Since ) if(
ifModSince lt lastModified ) doGet( req, resp
) else resp.setStatus( 304
)
4Servlet Classes
Interface
Servlet
Implements
Extends
JSPPage
GenericServlet
Extends
Extends
HttpJspPage _jspService
HttpServlet getLastModified
5JSP Wrapping Classes
HttpServlet service
JSPWrapper doGet - include JSP
MyJSPWrapper getLastModified
6class JSPWrapper extends HttpServlet public
void doGet( HttpServletRequest req,
HttpServletResponse resp ) String servletPath
req.getServletPath() String target
servletPath.substring( 0, servletPath.length()
- matchingSuffix.length() ) target
target targetSuffix String query
req.getQueryString() if( query ! null
) target target ? query req.getReque
stDispatcher( target ).include( req, resp
) String matchingSuffix .jsp,
targetSuffix .wjsp
7class MyJspWrapper extends JspWrapper public
long getLastModified( HttpServletRequest req )
if( lastModified -1 ) lastModified
System.currentTimeMillis() / 1000
1000 return lastModified long
lastModified -1
8JSPFile
GET foo.jsp
GET foo.jsp
JSP
JSPWrapper
doGet
MyJSPWrapper
include foo.wjsp
getLastModified
200
JSP
304
200