Java Reference
In-Depth Information
final byte[] bytes = new byte[1024];
while ((read = != -1) {
out.write(bytes, 0, read);
writer.println("New file " + fileName + " created at " + filepath);
LOGGER.log(Level.INFO, "File{0}being uploaded to {1}",
new Object[]{fileName, filepath});
} catch (FileNotFoundException fne) {
writer.println("You either did not specify a file to upload or are " +
"trying to upload a file to a protected or nonexistent location.");
writer.println("<br/> ERROR: " + fne.getMessage());
LOGGER.log(Level.SEVERE, "Problems during file upload. Error: {0}",
new Object[]{fne.getMessage()});
} finally {
if (writer != null) {
private String getFileName(final String path, HttpServletRequest req){
String name;
if (path.length() > 0 && path.charAt(0) == '/'){
name = path.substring(1);
} else {
name = path;
name.replace('/', File.pathSeparatorChar);
return req.getServletContext().getRealPath(name);
Filter Life Cycle
Some minor changes have been made in the filter life cycle of a servlet in release 3.1. In an effort to better understand
the changes, let's review the life cycle of a filter. After a web application is deployed but before the application can
begin serving requests, the container must locate the list of filters that are to be applied to the web resource. The list of
filters can be defined in the web.xml file or via annotations that have been applied to servlet classes. Only one instance
per <filter> declaration is instantiated per JVM of the container. When the container receives an incoming request,
it applies the first filter instance in the list of filters that need to be applied and calls its corresponding doFilter method.
For example, let's say that the web.xml file contains two filter specifications for the given servlet path: FilterA
and FilterB . When a servlet in the path is requested, both of these filters must be applied to the request. Therefore,
the first filter's doFilter method is invoked, and the filter is processed accordingly. Once complete, the next filter's
doFilter method is invoked, and so on. It is possible that a filter's doFilter method will invoke the next entity in
Search WWH ::

Custom Search