View Javadoc

1   package uk.ac.ebi.intenz.webapp.controller;
2   
3   import javax.servlet.ServletException;
4   import javax.servlet.RequestDispatcher;
5   import javax.servlet.ServletContext;
6   import javax.servlet.http.HttpServletRequest;
7   import javax.servlet.http.HttpServletResponse;
8   import java.io.IOException;
9   
10  /**
11   * All commands of this type do not need a connection to the database.
12   *
13   * @author Michael Darsow
14   * @version 0.9 - 21-July-2003
15   */
16  public abstract class NonDatabaseCommand extends Command {
17  
18    protected ServletContext context;
19  
20    protected HttpServletRequest request;
21  
22    protected HttpServletResponse response;
23  
24    /**
25     * Initialises the attributes which will be used to extract information for the command execution.
26     *
27     * @param context The servlet context.
28     * @param request The request object.
29     * @param response The response object.
30     */
31    public void init(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
32      this.context = context;
33      this.request = request;
34      this.response = response;
35    }
36  
37    /**
38     * Forwards to the given target.
39     *
40     * @param target A valid URI.
41     * @throws ServletException
42     * @throws IOException
43     */
44    protected void forward(String target) throws ServletException, IOException {
45      RequestDispatcher dispatcher = context.getRequestDispatcher(target);
46      dispatcher.forward(request, response);
47    }
48  }