Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
  6. version="3.1">
  7. <display-name>WebProject</display-name>
  8. <welcome-file-list>
  9. <welcome-file>index.jsp</welcome-file>
  10. </welcome-file-list>
  11. <servlet>
  12. <servlet-name>SpringDispatcherServlet</servlet-name>
  13. <servlet-
  14. class>org.springframework.web.servlet.DispatcherServlet</servlet-
  15. class>
  16. <init-param>
  17. <param-name>contextConfigLocation</param-name>
  18. <param-value>WEB-INF/config-mvc.xml</param-value>
  19. </init-param>
  20. </servlet>
  21. <servlet-mapping>
  22. <servlet-name>SpringDispatcherServlet</servlet-name>
  23. <url-pattern>*.do</url-pattern>
  24. </servlet-mapping>
  25. <context-param>
  26. <param-name>contextConfigLocation</param-name>
  27. <param-value>classpath:configApplication.xml</param-value>
  28. </context-param>
  29. </web-app>
  30.  
  31. <!doctype html>
  32. <html>
  33. <head>
  34. <meta charset="utf-8" />
  35. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  36. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
  37. <!-- Latest compiled and minified CSS -->
  38. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  39.  
  40. <!-- jQuery library -->
  41. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  42.  
  43. <!-- Latest compiled JavaScript -->
  44. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  45. <title>TPV Cocoa</title>
  46. <style>
  47. .formulario{
  48. margin: 0 auto;
  49. float: none;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div class="container-fluid">
  55. <h1 class="text-center">Inicia sesión en TPV Cocoa</h1>
  56. <form action="login.do" method="post">
  57. <div class="row">
  58. <div class="col-lg-4 col-lg-offset-4 col-sm-4 col-sm-offset-4">
  59. <div class="formulario form-group">
  60. <div class="input-group">
  61. <span class="input-group-addon"><i class="glyphicon
  62. glyphicon-user"></i></span>
  63. <input id="user" type="text" class="form-control"
  64. name="user" placeholder="Usuario" value="">
  65. </div>
  66. <br>
  67. <div class="input-group">
  68. <span class="input-group-addon"><i class="glyphicon
  69. glyphicon-lock"></i></span>
  70. <input id="password" type="password" class="form-control"
  71. name="password" placeholder="Password" value="">
  72. </div>
  73. <div>
  74. <c:out value="${requestScope.error}"/>
  75. </div>
  76. <br>
  77. <input type="submit" class="btn btn-default" value="Iniciar
  78. sesión"/>
  79. </div>
  80. </div>
  81. </div>
  82. </form>
  83. <div id="avisos" style="color:red"><?php echo $avisos ?></div>
  84. </div>
  85. <script>document.getElementById('usuario').focus();</script>
  86. </body>
  87. </html>
  88.  
  89. @Controller
  90. @ComponentScan("cocoa.tpv.controllers")
  91. public class UserController {
  92.  
  93. @Autowired
  94. UserFacade userService;
  95.  
  96.  
  97. @RequestMapping("login.do")
  98. public ModelAndView loginUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException{
  99. HttpSession session=request.getSession();
  100.  
  101. ModelAndView modelAndView=new ModelAndView();
  102. User user=new User();
  103.  
  104. String userName=request.getParameter("user");
  105. String userPassword=request.getParameter("password");
  106.  
  107. try{
  108. user.setName(userName);
  109. user.setPassword(userPassword);
  110.  
  111. User usuarioLogged=userService.getUser(user);
  112.  
  113. if(usuarioLogged == null){
  114. modelAndView.setViewName("index.jsp");
  115. }else{
  116. modelAndView.setViewName("main.jsp");
  117. modelAndView.addObject("usuarioLogged", usuarioLogged);
  118. }
  119.  
  120. }catch(MainException excepcion){
  121. modelAndView.setViewName("index.jsp");
  122. modelAndView.addObject("error", excepcion.getMessage());
  123. }
  124.  
  125. return modelAndView;
  126.  
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement