论坛首页 Web前端技术论坛

EXT Servelt Filter问题

浏览 1824 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-05-11  
EXT
只有一个filter
web.xml 
<filter>
  <filter-name>loginFilter</filter-name>
  <filter-class>com.app.LoginFilter</filter-class>
 </filter>
   
 <filter-mapping>
  <filter-name>loginFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>

LoginFilter.java
public void doFilter(ServletRequest request, ServletResponse response,
	   FilterChain chain) throws IOException, ServletException {
		 
               System.out.println("filter ......");
	      HttpServletRequest req=(HttpServletRequest)request;
	      HttpServletResponse res = (HttpServletResponse) response;
		  HttpSession session=req.getSession();
		  String   uri   =   req.getRequestURI();    
	if(session.getAttribute("user_role")!=null|| uri.endsWith("login.js")||uri.endsWith("login.jsp")||uri.endsWith("/sso/")) {
		      System.out.println("funcation ..");
		      chain.doFilter(req, res);   
		      return ;
		   }else{
  System.out.println("else..");
			RequestDispatcher dispatcher = req.getRequestDispatcher("login.jsp");     
	            dispatcher.forward(req, res);     	  
                     }
	     }
		  
	 }
login.jsp
<%@ include file="/common/packages.jsp"%>
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
	<script type="text/javascript" src="<%=ctx%>/login.js"></script>
	
  </head>
  
  <body>
  </body>
</html>

if(session.getAttribute("user_role")!=null|| uri.endsWith("login.js")||uri.endsWith("login.jsp")||uri.endsWith("/sso/")) 
成立后页面出现空白,没有下面执行,理想的效果是成立后返回login.jsp登陆页面。  不成立也返回login.jsp.因为是页面所以要跳过login.jsp页面判断。


现在的问题还有:
1、访问http://loclahost:8080/sso回车不执行filter,得点击刷新,才走filter,如果访问http://loclahost:8080/sso/fdsffs回车执行filter。
2、不明白为什么打印出这么多,把 /common/packages.jsp里的都打印出来了。
filter ......
/sso/
funcation ..
filter ......
/sso/ext/resources/css/ext-all.css
else..
filter ......
/sso/ext/examples/menu/menus.css
else..
filter ......
/sso/ext/examples/tabs/tab-scroller-menu.css
else..
filter ......
/sso/css/public.css
else..
filter ......
/sso/css/main.css
else..
filter ......
/sso/css/icon.css
else..
filter ......
/sso/ext/js/ext-base.js
else..
filter ......
/sso/js/Application.js
else..
filter ......
/sso/ext/js/ext-all.js
filter ......
else..
/sso/js/public.js
else..
filter ......
/sso/ext/examples/ux/ext-lang-zh_CN.js
else..
filter ......
/sso/ext/examples/ux/TabCloseMenu.js
else..
filter ......
/sso/ext/examples/ux/ux-all.js
else..
filter ......
/sso/login.js
funcation ..


3、目标是实现权限的控制。在EXT框架里会有这一些问题,但在搭建一个的servelt工程是没问题的。


论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics