Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. @Controller
  2. @RequestMapping("/users")
  3. public class UserController {
  4. @Autowired
  5. private UserService userService;
  6. @RequestMapping(value = "/list", method = RequestMethod.GET)
  7. public @ResponseBody
  8. List<User> getAllUsers() {
  9. return userService.getAllUsers();
  10. }
  11.  
  12. @RequestMapping(value = "/validate", method = RequestMethod.GET)
  13. public ModelAndView validateUser() {
  14. ModelAndView modelAndView = new ModelAndView();
  15. modelAndView.addObject("userFromServer", new User());
  16. modelAndView.setViewName("users_check_page");
  17. return modelAndView;
  18. }
  19. @RequestMapping(value = "/check", method = RequestMethod.POST)
  20. public @ResponseBody
  21. String checkUser(@ModelAttribute("userFromServer") User user) {
  22. if ("admin".equals(user.getName()) && "admin".equals(user.getPassword())) {
  23. return "valid";
  24. }
  25. return "invalid";
  26. }
  27. }
  28.  
  29. <build>
  30. <finalName>FirstAppwithJetty</finalName>
  31. <plugins>
  32. <plugin>
  33. <groupId>org.eclipse.jetty</groupId>
  34. <artifactId>jetty-maven-plugin</artifactId>
  35. <version>9.2.11.v20150529</version>
  36.  
  37. <configuration>
  38. <scanIntervalSeconds>10</scanIntervalSeconds>
  39. <httpConnector>
  40. <port>9751</port>
  41. </httpConnector>
  42. <webApp>
  43. <contextPath>/user-system</contextPath>
  44. </webApp>
  45. </configuration>
  46.  
  47. </plugin>
  48. <plugin>
  49. <groupId>org.apache.maven.plugins</groupId>
  50. <artifactId>maven-compiler-plugin</artifactId>
  51. <version>3.2</version>
  52. <configuration>
  53. <source>1.8</source>
  54. <target>1.8</target>
  55. </configuration>
  56. </plugin>
  57. </plugins>
  58. </build>
  59.  
  60. <?xml version="1.0" encoding="UTF-8"?>
  61. <beans xmlns="http://www.springframework.org/schema/beans"
  62. xmlns:context="http://www.springframework.org/schema/context"
  63. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  64. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  65.  
  66. <mvc:annotation-driven/>
  67.  
  68. <context:component-scan base-package="system"/>
  69.  
  70. <mvc:view-controller path="/" view-name="users_page"/>
  71. <mvc:view-controller path="/test/" view-name="test"/>
  72.  
  73. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  74. <property name="prefix" value="/WEB-INF/pages/"/>
  75. <property name="suffix" value=".jsp"/>
  76. </bean>
  77. </beans>
  78.  
  79. <?xml version="1.0" encoding="UTF-8"?>
  80. <web-app xmlns="http://java.sun.com/xml/ns/javaee"
  81. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  82. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  83. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  84. version="3.0">
  85.  
  86. <servlet>
  87. <servlet-name>dispatcher</servlet-name>
  88. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  89. <init-param>
  90. <param-name>contextConfigLocation</param-name>
  91. <param-value>/WEB-INF/spring/spring-config.xml</param-value>
  92. </init-param>
  93. <load-on-startup>1</load-on-startup>
  94. </servlet>
  95.  
  96. <servlet-mapping>
  97. <servlet-name>dispatcher</servlet-name>
  98. <url-pattern>/</url-pattern>
  99. </servlet-mapping>
  100. </web-app>
  101.  
  102. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  103. <html>
  104. <head>
  105. <title>Title</title>
  106. </head>
  107. <body>
  108. <spring:form modelAttribute="userFromServer" method="post" action="/user-system/users/check">
  109. <spring:input path="name"/>
  110. <spring:input path="password"/>
  111. <spring:button>check user</spring:button>
  112. </spring:form>
  113. </body>
  114. </html>
Add Comment
Please, Sign In to add comment