Java Web Programming with Eclipse contents
Last modified March 11, 2010 06:34 pm

back next

Wiki Application (continued)

Exercises

(1) Confirming Cancelations

When the user cancels the publish operation, he or she is brought back to the view page. The text mentioned that the user can verify that the operation was canceled by seeing the publish link in the view page as opposed to the unpublish link. Devise and implement a way to explicitly state to the user that the operation was cancelled.

(2) Exception Catching Filter

Create and configure a filter to catch exceptions thrown in your code and make these exceptions appear in your log file. This makes it easier to see exceptions because you do not need to look into a different log file to see exceptions. To do this, do the following. Create a class called LogFilter that implements the javax.servlet.Filter interface. Add the following code to the doFilter method.

try {
   arg2.doFilter(arg0, arg1);
} catch (Exception e) {
   logger.error("", e);
   throw new ServletException(e);
}

Add the following code to web.xml.

   <filter>
      <filter-name>log-filter</filter-name>
      <filter-class>wiki.web.LogFilter</filter-class>

   </filter>
   <filter-mapping>
      <filter-name>log-filter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

Test that exceptions are now written to your log file by introducing a bug into your code.

(3) Redirection

Currently, requests for http://localhost:8080/wiki/view do work correctly. Implement a redirection servlet that gets requests for http://localhost:8080/wiki/view and returns a redirection command to the browser to go to http://localhost:8080/wiki/view/.

back next

Copyright 2007-2009 David Turner and Jinseok Chae. All rights reserved.