Commits

conanca committed 713aef3

登录失败时返回登录页

Comments (0)

Files changed (3)

src/main/java/com/dolplay/nutzshiro/filter/AuthenticationFilter.java

 import org.nutz.mvc.Mvcs;
 import org.nutz.mvc.View;
 import org.nutz.mvc.view.JspView;
+import org.nutz.mvc.view.ViewWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.dolplay.nutzshiro.util.MvcUtils;
 
 public class AuthenticationFilter implements ActionFilter {
+	final static Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
+
 	public static final String DEFAULT_USERNAME_PARAM = "username";
 	public static final String DEFAULT_PASSWORD_PARAM = "password";
 	public static final String DEFAULT_REMEMBER_ME_PARAM = "rememberMe";
 			try {
 				boolean isLogin = executeLogin(actionContext.getRequest(), actionContext.getResponse());
 				if (!isLogin) {
-//					Map<String,String> msgs = Mvcs.getLocaleMessage("zh_CN");
-//					String errMsg = msgs.get("login_error");
-					view = new JspView("jsp.error");
+					Map<String, Object> msgs = Mvcs.getLocaleMessage("zh_CN");
+					String errMsg = msgs.get("login_error").toString();
+					view = new ViewWrapper(new JspView("/index"), errMsg);
+					logger.info("登录失败");
 				}
 			} catch (Exception e) {
-				view = new JspView("jsp.error");
+				view = new ViewWrapper(new JspView("/index"), "登录出错");
 			}
 		}
 

src/main/webapp/WEB-INF/jsp/error.jsp

-<%@ page language="java" contentType="text/html; charset=UTF-8"
-    pageEncoding="UTF-8"%>
-<%@ page isELIgnored="false" %>
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<%
-  String path = request.getContextPath();
-  String basePath = request.getScheme() + "://"
-      + request.getServerName() + ":" + request.getServerPort()
-      + path + "/";
-%>
-<base href="<%=basePath%>" />
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>错误</title>
-</head>
-<body>
-  <h2>${msg.login_error}</h2>
-  <a href="index.jsp">返回</a>
-</body>
-</html>

src/main/webapp/index.jsp

-<%@ page language="java" contentType="text/html; charset=UTF-8"
-  pageEncoding="UTF-8"%>
+<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<%@ page isELIgnored="false" %>
 <!DOCTYPE html>
 <html lang="en">
 <head>
   <form action="login" class="form-vertical">
     <fieldset>
       <legend>请登录</legend>
+      <div id="alert">
+      ${obj}
+      </div>
       <div class="control-group">
         <label class="control-label" for="username">${msg.login_name}</label>
         <div class="controls">
     </fieldset>
   </form>
   </div>
+  <script src="js/jquery-1.7.2.min.js"></script>
   <script src="js/bootstrap.min.js"></script>
+  <script type="text/javascript">
+    var msg = '${obj}';
+    if(msg){
+    	$('#alert').addClass('alert alert-error');
+    	$('#alert').append('<a class="close" data-dismiss="alert">×</a>');
+    }
+  </script>
 </body>
 </html>