Java Doc for ResourceServlet.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.servlet 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.springframework.web.servlet.HttpServletBean
   org.springframework.web.servlet.ResourceServlet

ResourceServlet
public class ResourceServlet extends HttpServletBean (Code)
Simple servlet that can expose an internal resource, including a default URL if the specified resource is not found. An alternative, for example, to trying and catching exceptions when using JSP include.

A further usage of this servlet is the ability to apply last-modified timestamps to quasi-static resources (typically JSPs). This can happen as bridge to parameter-specified resources, or as proxy for a specific target resource (or a list of specific target resources to combine).

A typical usage would map a URL like "/ResourceServlet" onto an instance of this servlet, and use the "JSP include" action to include this URL, with the "resource" parameter indicating the actual target path in the WAR.

The defaultUrl property can be set to the internal resource path of a default URL, to be rendered when the target resource is not found or not specified in the first place.

The "resource" parameter and the defaultUrl property can also specify a list of target resources to combine. Those resources will be included one by one to build the response. If last-modified determination is active, the newest timestamp among those files will be used.

The allowedResources property can be set to a URL pattern of resources that should be available via this servlet. If not set, any target resource can be requested, including resources in the WEB-INF directory!

If using this servlet for direct access rather than via includes, the contentType property should be specified to apply a proper content type. Note that a content type header in the target JSP will be ignored when including the resource via a RequestDispatcher include.

To apply last-modified timestamps for the target resource, set the applyLastModified property to true. This servlet will then return the file timestamp of the target resource as last-modified value, falling back to the startup time of this servlet if not retrievable.

Note that applying the last-modified timestamp in the above fashion just makes sense if the target resource does not generate content that depends on the HttpSession or cookies; it is just allowed to evaluate request parameters.

A typical case for such last-modified usage is a JSP that just makes minimal usage of basic means like includes or message resolution to build quasi-static content. Regenerating such content on every request is unnecessary; it can be cached as long as the file hasn't changed.

Note that this servlet will apply the last-modified timestamp if you tell it to do so: It's your decision whether the content of the target resource can be cached in such a fashion. Typical use cases are helper resources that are not fronted by a controller, like JavaScript files that are generated by a JSP (without depending on the HttpSession).
author:
   Rod Johnson
author:
   Juergen Hoeller
See Also:   ResourceServlet.setDefaultUrl
See Also:   ResourceServlet.setAllowedResources
See Also:   ResourceServlet.setApplyLastModified



Field Summary
final public static  StringRESOURCE_PARAM_NAME
     Name of the parameter that must contain the actual resource path.
final public static  StringRESOURCE_URL_DELIMITERS
     Any number of these characters are considered delimiters between multiple resource paths in a single String value.


Method Summary
protected  StringdetermineResourceUrl(HttpServletRequest request)
     Determine the URL of the target resource of this request.
final protected  voiddoGet(HttpServletRequest request, HttpServletResponse response)
     Determine the URL of the target resource and include it.
protected  longgetFileTimestamp(String resourceUrl)
     Return the file timestamp for the given resource.
final protected  longgetLastModified(HttpServletRequest request)
     Return the last-modified timestamp of the file that corresponds to the target resource URL (i.e.
protected  PathMatchergetPathMatcher()
     Return a PathMatcher to use for matching the "allowedResources" URL pattern.
protected  voidinitServletBean()
     Remember the startup time, using no last-modified time before it.
public  voidsetAllowedResources(String allowedResources)
     Set allowed resources as URL pattern, e.g.
public  voidsetApplyLastModified(boolean applyLastModified)
     Set whether to apply the file timestamp of the target resource as last-modified value.
public  voidsetContentType(String contentType)
     Set the content type of the target resource (typically a JSP).
public  voidsetDefaultUrl(String defaultUrl)
     Set the URL within the current web application from which to include content if the requested path isn't found, or if none is specified in the first place.

If specifying multiple URLs, they will be included one by one to build the response.


Field Detail
RESOURCE_PARAM_NAME
final public static String RESOURCE_PARAM_NAME(Code)
Name of the parameter that must contain the actual resource path.



RESOURCE_URL_DELIMITERS
final public static String RESOURCE_URL_DELIMITERS(Code)
Any number of these characters are considered delimiters between multiple resource paths in a single String value.





Method Detail
determineResourceUrl
protected String determineResourceUrl(HttpServletRequest request)(Code)
Determine the URL of the target resource of this request.

Default implementation returns the value of the "resource" parameter. Can be overridden in subclasses.
Parameters:
  request - current HTTP request the URL of the target resource, or null if none found
See Also:   ResourceServlet.RESOURCE_PARAM_NAME




doGet
final protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException(Code)
Determine the URL of the target resource and include it.
See Also:   ResourceServlet.determineResourceUrl



getFileTimestamp
protected long getFileTimestamp(String resourceUrl)(Code)
Return the file timestamp for the given resource.
Parameters:
  resourceUrl - the URL of the resource the file timestamp in milliseconds,or -1 if not determinable



getLastModified
final protected long getLastModified(HttpServletRequest request)(Code)
Return the last-modified timestamp of the file that corresponds to the target resource URL (i.e. typically the request ".jsp" file). Will simply return -1 if "applyLastModified" is false (the default).

Returns no last-modified date before the startup time of this servlet, to allow for message resolution etc that influences JSP contents, assuming that those background resources might have changed on restart.

Returns the startup time of this servlet if the file that corresponds to the target resource URL coudln't be resolved (for example, because the WAR is not expanded).
See Also:   ResourceServlet.determineResourceUrl
See Also:   ResourceServlet.getFileTimestamp




getPathMatcher
protected PathMatcher getPathMatcher()(Code)
Return a PathMatcher to use for matching the "allowedResources" URL pattern. Default is AntPathMatcher.
See Also:   ResourceServlet.setAllowedResources
See Also:   org.springframework.util.AntPathMatcher



initServletBean
protected void initServletBean()(Code)
Remember the startup time, using no last-modified time before it.



setAllowedResources
public void setAllowedResources(String allowedResources)(Code)
Set allowed resources as URL pattern, e.g. "/WEB-INF/res/*.jsp", The parameter can be any Ant-style pattern parsable by AntPathMatcher.
See Also:   org.springframework.util.AntPathMatcher



setApplyLastModified
public void setApplyLastModified(boolean applyLastModified)(Code)
Set whether to apply the file timestamp of the target resource as last-modified value. Default is "false".

This is mainly intended for JSP targets that don't generate session-specific or database-driven content: Such files can be cached by the browser as long as the last-modified timestamp of the JSP file doesn't change.

This will only work correctly with expanded WAR files that allow access to the file timestamps. Else, the startup time of this servlet is returned.




setContentType
public void setContentType(String contentType)(Code)
Set the content type of the target resource (typically a JSP). Default is none, which is appropriate when including resources.

For directly accessing resources, for example to leverage this servlet's last-modified support, specify a content type here. Note that a content type header in the target JSP will be ignored when including the resource via a RequestDispatcher include.




setDefaultUrl
public void setDefaultUrl(String defaultUrl)(Code)
Set the URL within the current web application from which to include content if the requested path isn't found, or if none is specified in the first place.

If specifying multiple URLs, they will be included one by one to build the response. If last-modified determination is active, the newest timestamp among those files will be used.
See Also:   ResourceServlet.setApplyLastModified




Fields inherited from org.springframework.web.servlet.HttpServletBean
final protected Log logger(Code)(Java Doc)

Methods inherited from org.springframework.web.servlet.HttpServletBean
final protected void addRequiredProperty(String property)(Code)(Java Doc)
final public ServletContext getServletContext()(Code)(Java Doc)
final public String getServletName()(Code)(Java Doc)
final public void init() throws ServletException(Code)(Java Doc)
protected void initBeanWrapper(BeanWrapper bw) throws BeansException(Code)(Java Doc)
protected void initServletBean() throws ServletException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.