我想通过过滤器验证用户是否登录,用户登录了就能执行相应的操作,没有登录,就跳转到登录页面。因为我对过滤器不是很懂,哪个高手帮个忙,解决一下,感激了
------解决方案--------------------
给个简短例子吧:
- XML code
<filter> <filter-name>SessionValidFilter</filter-name> <filter-class>web.filter.SessionValidFilter</filter-class> </filter> <filter-mapping> <filter-name>SessionValidFilter</filter-name> <url-pattern>/jsp/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionValidFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionValidFilter</filter-name> <url-pattern>/servlet/*</url-pattern> </filter-mapping>
------解决方案--------------------
写个类,继承Filter。
然后在web.xml里面添加拦截
- XML code
<filter> <filter-name>filter名</filter-name> <filter-class>你的filter类路径</filter-class> </filter> <filter-mapping> <filter-name>filter名</filter-name> <url-pattern>你要拦截的路径,如:/*</url-pattern> </filter-mapping>