The following screen shots show how to create a filter in JDeveloper.
Begin by adding a new Servlet Filter to the project:
Speify the name of the filter in step one of the filter wizard:
In the next step specify that all requests to the /calculator URL should pass through the age filter:
And now implement the doFilter method:
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws
IOException, ServletException {
int
age = new Integer(request.getParameter("age"));
if
(age < 65) {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Calculator</title></head>");
out.println("<body>");
out.println(
"sorry, you must be
at least 65 years old.");
out.println("</body></html>");
out.close();
return;
}
chain.doFilter(request, response);
}
Note that only if the age is 65 or greater will the request be passed on to the next filter in the chain. If there are no more filters in the chain, then the request will be passed on to the /calculator URL, which is the servlet.
For example, when the user enters an age below 65:
Then the filter does not pass the request on: