我的项目是用struts1.2 做的,我的jsp页面跳转都是通过配制文件进行跳转的, <!--菜单出勤天数统计跳转 -->
<action path="/T_attendancedate"
type="org.apache.struts.actions.ForwardAction"
parameter="/principalconsulting/attendancedate.jsp?key=1" />
这个是我的过滤器,public class LoginFilter extends HttpServlet implements Filter { @Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain china) throws IOException, ServletException {
HttpServletRequest res = (HttpServletRequest) request;
HttpServletResponse respon = (HttpServletResponse) response;
HttpSession session = res.getSession();
if (session.getAttribute("name") == null) {
respon.sendRedirect(res.getContextPath() + "/loginno.do");
System.out.println("非法登陆");
} else {
china.doFilter(request, response);
}
} @Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
// System.out.println("****");
}}//这个是我的web.xml <filter>
<filter-name>login</filter-name>
<filter-class>loginfilter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>login</filter-name>
<url-pattern>/rxdj/*</url-pattern>
</filter-mapping>现在的问题是这样的,我用http://localhost:8080/NMSoftware/principalconsulting/attendancedate.jsp?key=1这个地址直接访问jsp页面,是可以过滤的,但是我用,http://localhost:8080/NMSoftware/T_attendancedate.do 通过配制文件在访问就过滤不到了,,,,,,,,,,,大家帮帮忙看下啊。
<action path="/T_attendancedate"
type="org.apache.struts.actions.ForwardAction"
parameter="/principalconsulting/attendancedate.jsp?key=1" />
这个是我的过滤器,public class LoginFilter extends HttpServlet implements Filter { @Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain china) throws IOException, ServletException {
HttpServletRequest res = (HttpServletRequest) request;
HttpServletResponse respon = (HttpServletResponse) response;
HttpSession session = res.getSession();
if (session.getAttribute("name") == null) {
respon.sendRedirect(res.getContextPath() + "/loginno.do");
System.out.println("非法登陆");
} else {
china.doFilter(request, response);
}
} @Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
// System.out.println("****");
}}//这个是我的web.xml <filter>
<filter-name>login</filter-name>
<filter-class>loginfilter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>login</filter-name>
<url-pattern>/rxdj/*</url-pattern>
</filter-mapping>现在的问题是这样的,我用http://localhost:8080/NMSoftware/principalconsulting/attendancedate.jsp?key=1这个地址直接访问jsp页面,是可以过滤的,但是我用,http://localhost:8080/NMSoftware/T_attendancedate.do 通过配制文件在访问就过滤不到了,,,,,,,,,,,大家帮帮忙看下啊。
有这个过滤器吗,你第一种写法是直接请求action了,当然给你响应了!
你的拦截有问题。改成拦截所有 去掉rxdj
如果改成这样,<url-pattern>/rxdj/*</url-pattern>
那么登陆login.jsp页面也过滤了,这样就会一直在login.jsp,不断刷新,,登陆不进去啊。
<url-pattern>/*</url-pattern>//改成这样,就进不去登陆页面啦。是不行的。
type="org.apache.struts.actions.ForwardAction"
parameter="/principalconsulting/attendancedate.jsp?key=1" />
parameter 是决定你调用方法的参数属性
跳转页面时用<forward >节点
如
<action path="/news" type="com.ambow.struts.action.NewsAction" parameter="method">
<forward name="query" path="/news.jsp"/>
<forward name="list" path="/news.do?method=query"/>
</action>
我也不能把所有的jsp页面都放在一个夹下啊,这样管理起来太麻烦啦。
我说老大~您不会在过滤器里面把login .jsp和它相关的样式表和图片放开让他通过啊~
在filter里面判断一下啊~
if(request.getServletPath().equalsIgnoreCase("/admins/login.jsp")){
chain.doFilter(arg0, arg1);
}
if(判断请求路径是否是jsp或者.do){
if(判断请求路径是否是/login.jsp)){
//放过
}else{
//跳转到错误页或者登录页
}
}else{
//不是jsp或者.do的其它请求放过
}
}else{
//有登录信息的所有放过~
}
http://localhost:8080/NMSoftware/Alclo.do,http://localhost:8080/NMSoftware/rxde/student.jsp 这两个地址是可以拦截了,但是我现在访问这个地址http://localhost:8080/NMSoftware/Alclo.do?method=adString 就是后带了人方法,就报错了。。这样过滤器就不拦截了,,,,。
那样他只会拦截/rxdj下面的东西~其它的不会拦截~
映射成/rxdj/Alclo
如果我登陆成功,我在直接访问http://localhost:8080/NMSoftware/Alclo.do?method=adString这个带参数的地址就会出错,。