User's Manual

Chapter 8. WAF Application Development Tutorial 59
/**
* A servlet to serve pages of the binder application.
*
* @see com.example.binder.Binder
* @author Justin Ross
*/
public final class BinderServlet extends BaseApplicationServlet {
private static final Logger s_log = Logger.getLogger(BinderServlet.class);
public void doService(final HttpServletRequest sreq,
final HttpServletResponse sresp,
final Application app)
throws ServletException, IOException {
sresp.getWriter().write("YO");
}
}
Example 8-9. binder/src/com/example/binder/BinderServlet.java
An Application is associated with a path into the servlet container. The WAF dispatcher will look up
your application and use its getContextPath and getServletPath methods to dispatch to your
UI code. Our webapp will be mounted as binder in the servlet container, so we specify Binder’s
context path to be /binder.
public final String getContextPath() {
return "/binder";
}
Example 8-10. Setting the application’s dispatch destination
When the dispatcher encounters a request for an instance of the binder application, it will look up the
appropriate Binder object and use its getContextPath and getServletPath methods to dispatch
to the appropriate servlet code, in this case BinderServlet.
By specifying the servlet path this way, we index into the servlet container’s native method of dispatch,
by pattern. Your servlet container uses a webapp-standard file web.xml to declare pattern-to-servlet
mappings.
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>binder</servlet-name>
<servlet-class>com.example.binder.BinderServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>binder</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Example 8-11. binder/web/WEB-INF/web.xml