Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- </dependency>
- <dependency>
- <groupId>jstl</groupId>
- <artifactId>jstl</artifactId>
- <version>1.2</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.1.1</version>
- <configuration>
- <webXml>webWEB-INFweb.xml</webXml>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
- public class Controller extends HttpServlet {
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- private void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String page = null;
- // определение команды, пришедшей из JSP
- ActionFactory client = new ActionFactory();
- ActionCommand command = client.defineCommand(request);
- // вызов реализованного метода execute() и передача параметров классу-обработчику конкретной команды
- page = command.execute(request);
- // метод возвращает страницу ответа
- if (page != null) {
- RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page); // вызов страницы ответа на запрос
- dispatcher.forward(request, response);
- } else {
- // установка страницы c cообщением об ошибке
- page = ConfigurationManager.getProperty("path.page.index");
- request.getSession().setAttribute("nullPage", MessageManager.getProperty("message.nullpage"));
- response.sendRedirect(request.getContextPath() + page);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement