Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
- http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
- version="3.1">
- <display-name>WebProject</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <servlet-name>SpringDispatcherServlet</servlet-name>
- <servlet-
- class>org.springframework.web.servlet.DispatcherServlet</servlet-
- class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>WEB-INF/config-mvc.xml</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>SpringDispatcherServlet</servlet-name>
- <url-pattern>*.do</url-pattern>
- </servlet-mapping>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:configApplication.xml</param-value>
- </context-param>
- </web-app>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8" />
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <!-- jQuery library -->
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <!-- Latest compiled JavaScript -->
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- <title>TPV Cocoa</title>
- <style>
- .formulario{
- margin: 0 auto;
- float: none;
- }
- </style>
- </head>
- <body>
- <div class="container-fluid">
- <h1 class="text-center">Inicia sesión en TPV Cocoa</h1>
- <form action="login.do" method="post">
- <div class="row">
- <div class="col-lg-4 col-lg-offset-4 col-sm-4 col-sm-offset-4">
- <div class="formulario form-group">
- <div class="input-group">
- <span class="input-group-addon"><i class="glyphicon
- glyphicon-user"></i></span>
- <input id="user" type="text" class="form-control"
- name="user" placeholder="Usuario" value="">
- </div>
- <br>
- <div class="input-group">
- <span class="input-group-addon"><i class="glyphicon
- glyphicon-lock"></i></span>
- <input id="password" type="password" class="form-control"
- name="password" placeholder="Password" value="">
- </div>
- <div>
- <c:out value="${requestScope.error}"/>
- </div>
- <br>
- <input type="submit" class="btn btn-default" value="Iniciar
- sesión"/>
- </div>
- </div>
- </div>
- </form>
- <div id="avisos" style="color:red"><?php echo $avisos ?></div>
- </div>
- <script>document.getElementById('usuario').focus();</script>
- </body>
- </html>
- @Controller
- @ComponentScan("cocoa.tpv.controllers")
- public class UserController {
- @Autowired
- UserFacade userService;
- @RequestMapping("login.do")
- public ModelAndView loginUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException{
- HttpSession session=request.getSession();
- ModelAndView modelAndView=new ModelAndView();
- User user=new User();
- String userName=request.getParameter("user");
- String userPassword=request.getParameter("password");
- try{
- user.setName(userName);
- user.setPassword(userPassword);
- User usuarioLogged=userService.getUser(user);
- if(usuarioLogged == null){
- modelAndView.setViewName("index.jsp");
- }else{
- modelAndView.setViewName("main.jsp");
- modelAndView.addObject("usuarioLogged", usuarioLogged);
- }
- }catch(MainException excepcion){
- modelAndView.setViewName("index.jsp");
- modelAndView.addObject("error", excepcion.getMessage());
- }
- return modelAndView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement