如以下代码:
public class MyIntercepter extends AbstractInterceptor {
public String intercept(ActionInvocation ai) throws Exception {
User user = (User) ActionContext.getContext().getSession().get("user");
if (user!=null) {
return ai.invoke();
}else{
LoginAction loginAction = (LoginAction) ai.getAction();
loginAction.addActionError("你没登录,请先登录");
return Action.INPUT;
}
}
}
报错:java.lang.ClassCastException: com.opensymphony.xwork2.ActionSupport cannot be cast to com.ibm.action.LoginAction
按理说这样写没错啊 - -,ActionSupport类的实例竟然不能赋给 继承ActionSupport的类实例吗
struts.xml配置:
<action name="*">
<result>/WEB-INF/content/{1}.jsp</result>
<result name="input">/WEB-INF/content/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="myIntercepter"></interceptor-ref>
</action>
<action name="*"><!--原因出现在这里,没有配置对应的class-->
<result>/WEB-INF/content/{1}.jsp</result>
<result name="input">/WEB-INF/content/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="myIntercepter"></interceptor-ref>
</action>