Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Controller
- @RequestMapping("/users")
- public class UserController {
- @Autowired
- private UserService userService;
- @RequestMapping(value = "/list", method = RequestMethod.GET)
- public @ResponseBody
- List<User> getAllUsers() {
- return userService.getAllUsers();
- }
- @RequestMapping(value = "/validate", method = RequestMethod.GET)
- public ModelAndView validateUser() {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("userFromServer", new User());
- modelAndView.setViewName("users_check_page");
- return modelAndView;
- }
- @RequestMapping(value = "/check", method = RequestMethod.POST)
- public @ResponseBody
- String checkUser(@ModelAttribute("userFromServer") User user) {
- if ("admin".equals(user.getName()) && "admin".equals(user.getPassword())) {
- return "valid";
- }
- return "invalid";
- }
- }
- <build>
- <finalName>FirstAppwithJetty</finalName>
- <plugins>
- <plugin>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-maven-plugin</artifactId>
- <version>9.2.11.v20150529</version>
- <configuration>
- <scanIntervalSeconds>10</scanIntervalSeconds>
- <httpConnector>
- <port>9751</port>
- </httpConnector>
- <webApp>
- <contextPath>/user-system</contextPath>
- </webApp>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
- 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">
- <mvc:annotation-driven/>
- <context:component-scan base-package="system"/>
- <mvc:view-controller path="/" view-name="users_page"/>
- <mvc:view-controller path="/test/" view-name="test"/>
- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/pages/"/>
- <property name="suffix" value=".jsp"/>
- </bean>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
- <servlet>
- <servlet-name>dispatcher</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/spring-config.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>dispatcher</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- </web-app>
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>Title</title>
- </head>
- <body>
- <spring:form modelAttribute="userFromServer" method="post" action="/user-system/users/check">
- <spring:input path="name"/>
- <spring:input path="password"/>
- <spring:button>check user</spring:button>
- </spring:form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment