Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6.  
  7. <dependencies>
  8. <dependency>
  9. <groupId>javax.servlet</groupId>
  10. <artifactId>javax.servlet-api</artifactId>
  11. <version>3.1.0</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>jstl</groupId>
  15. <artifactId>jstl</artifactId>
  16. <version>1.2</version>
  17. </dependency>
  18. </dependencies>
  19.  
  20. <build>
  21. <plugins>
  22. <plugin>
  23. <groupId>org.apache.maven.plugins</groupId>
  24. <artifactId>maven-war-plugin</artifactId>
  25. <version>2.1.1</version>
  26. <configuration>
  27. <webXml>webWEB-INFweb.xml</webXml>
  28. </configuration>
  29. </plugin>
  30. </plugins>
  31. </build>
  32. </project>
  33.  
  34. public class Controller extends HttpServlet {
  35.  
  36. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  37. throws ServletException, IOException {
  38. processRequest(request, response);
  39. }
  40.  
  41. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  42. throws ServletException, IOException {
  43. processRequest(request, response);
  44. }
  45.  
  46. private void processRequest(HttpServletRequest request, HttpServletResponse response)
  47. throws ServletException, IOException {
  48. String page = null;
  49. // определение команды, пришедшей из JSP
  50. ActionFactory client = new ActionFactory();
  51. ActionCommand command = client.defineCommand(request);
  52. // вызов реализованного метода execute() и передача параметров классу-обработчику конкретной команды
  53. page = command.execute(request);
  54. // метод возвращает страницу ответа
  55. if (page != null) {
  56. RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page); // вызов страницы ответа на запрос
  57. dispatcher.forward(request, response);
  58. } else {
  59. // установка страницы c cообщением об ошибке
  60. page = ConfigurationManager.getProperty("path.page.index");
  61. request.getSession().setAttribute("nullPage", MessageManager.getProperty("message.nullpage"));
  62. response.sendRedirect(request.getContextPath() + page);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement