Java Reference
In-Depth Information
<security-constraint>
<web-resource-collection>
<web-resource-name>secured</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>users</role-name>
</auth-constraint>
</security-constraint>
In contrast, the following could be specified in a Servlet 3.1 application in order to deny any http method that is
uncovered without explicitly listing them within the web.xml .
<deny-uncovered-http-methods/>
Changing the Content Length
Sometimes it is useful to manually set the content length of a servlet header by invoking the ServletRequest
setContentLength method. Usually this is done to help facilitate the creation of certain types of documents, among
other reasons. The Servlet API has always allowed you to get or set the content length in byte format using the Java
int type. With the inception of Servlet 3.1, it is also possible to utilize the long data type for working with the content
length. This can aid in the scenario where a content length greater than 2GB needs to be specified. In previous
releases, setting a long value that was equal to 2GB would cause a negative header to be sent. The following methods
have been added to the Servlet API for utilizing the long data type:
ServletRequest.getContentLengthLong
ServletResponse.setContentLengthLong
Summary
The Servlet 3.1 specification includes many nice enhancements. The non-blocking I/O support makes Servlets more
feasible for producing modern web applications that utilize asynchronous operations. The ability to easily upgrade
protocol allows Servlet processing to change and allows for full-duplex protocol usage, when needed. The other
updates that have been outlined in this chapter also help to enhance the Servlet API, making it less cumbersome to
develop robust solutions.
It should be noted that many smaller enhancements to the API have been made that were not addressed in the
chapter. For a complete list of changes, please see the Servlet 3.1 documentation, which can be found at the
JSR 340 Specification website: ( http://jcp.org/en/jsr/detail?id=340 ) .
 
Search WWH ::




Custom Search