日期:2014-05-19  浏览次数:20627 次

struts2拦截器 跳转的问题 实在搞不清楚 请高人解答!
struts.xml 代码
<package name="default" extends="struts-default">
<!-- 拦截器设定 -->
<interceptors>
<interceptor name="consoleAuthority"
class="com.wondersgroup.login.util.AuthorCheckInterceptor">
<!-- 排除的方法 -->
<param name="excludeMethods">operate</param>
</interceptor>
<interceptor name="charInterceptor" class="com.wondersgroup.framework.util.CharInterceptor"/>

<interceptor-stack name="myChar">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="charInterceptor"/>
</interceptor-stack>

</interceptors>

<!-- 配置自定义的全局拦截器 -->
<default-interceptor-ref name="myChar" />

<!-- 全局返回路径 -->
<global-results>
<result name="login" type="redirect">login.jsp</result>
</global-results>

<!-- 配置全局异常映射 -->
<global-exception-mappings>
<exception-mapping exception="java.lang.Exceptions"
result="error" />
<exception-mapping result="error"
exception="java.lang.Throwable">
</exception-mapping>
</global-exception-mappings>
</package>

java代码

public class CharInterceptor implements Interceptor{
@Override
public String intercept(ActionInvocation invo) throws Exception {
String result = invo.invoke();
ActionContext atx = invo.getInvocationContext();
HttpServletRequest request=(HttpServletRequest)atx.get(StrutsStatics.HTTP_REQUEST); 
HttpServletResponse response=(HttpServletResponse)atx.get(StrutsStatics.HTTP_RESPONSE); 
Enumeration params = request.getParameterNames();
String param = "";
String paramValue = "";
boolean status = false;
while (params.hasMoreElements()) {
param = (String) params.nextElement();
String[] values = request.getParameterValues(param);
paramValue = "";
for (int i = 0; i < values.length; i++) {
paramValue = paramValue + values[i];
if (!transformSpace(paramValue)){
status = true;
break;
}
}
if (status) break;
}
if (status) {
return Action.LOGIN;
}else{
return result;
}
}

问题:程序走完return Action.LOGIN;后,页面没有跳转,程序也不报错,实在没办法,请高人帮忙解答。。。

------解决方案--------------------
<result name="login" type="redirect">login.jsp</result> 这个页面login.jsp是在WEB根目录下么,看看路径是否对
------解决方案--------------------
如果路径是对的 login.jsp前面因该要加“/”<result name="login" type="redirect">/login.jsp</result>
------解决方案--------------------
<result name="login" type="redirect">/login.jsp</result>
------解决方案--------------------
在这里给你几个建议:
1,如果如果浏览器提示404,找不到资源的错误,应该是配视图路径时出错。
2,去检查一下你写的Interceptor,有没有正确反回结果。
3,在Interceptor中打印一些提示语句,会对你有帮助。