我用struts 1.2框架写程序,我希望通过一个链接,到一个Action类中的一个方法,这个方法处理后,跳转到另一个页面
<html:link action="checkQuestion.do?method=check">查看我发布的问题></html:link>
struts-config.xml中的配置如下:
<action
path="/checkQuestion"
parameter="method"
scope="request"
type="com.fhj.struts.action.CheckQuestionAction">
<set-property property="cancellable" value="true" />
<forward name="success" path="/question/querymyquestion.jsp" />
</action>
我的CheckQuestionAction如下:
public class CheckQuestionAction extends Action {
public ActionForward check(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("I am in the CheckQuestionAction:check22");
return new ActionForward(mapping.findForward("success"));
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("I am in the CheckQuestionAction:execute22");
return new ActionForward(mapping.findForward("success"));
}
}我的<html:link action="checkQuestion.do?method=check">查看我发布的问题></html:link>调用的是check方法,但是实际调用的却是execute,不知道我哪里配置错误了?
<html:link action="checkQuestion.do?method=check">查看我发布的问题></html:link>
struts-config.xml中的配置如下:
<action
path="/checkQuestion"
parameter="method"
scope="request"
type="com.fhj.struts.action.CheckQuestionAction">
<set-property property="cancellable" value="true" />
<forward name="success" path="/question/querymyquestion.jsp" />
</action>
我的CheckQuestionAction如下:
public class CheckQuestionAction extends Action {
public ActionForward check(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("I am in the CheckQuestionAction:check22");
return new ActionForward(mapping.findForward("success"));
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("I am in the CheckQuestionAction:execute22");
return new ActionForward(mapping.findForward("success"));
}
}我的<html:link action="checkQuestion.do?method=check">查看我发布的问题></html:link>调用的是check方法,但是实际调用的却是execute,不知道我哪里配置错误了?
调用Action的类,一定会执行execute方法。
因为你没重写Action类的execute方法,不会分发请求。
<action
path="/checkQuestion"
parameter="method"
scope="request"
type="com.fhj.struts.action.CheckQuestionAction">
<set-property property="cancellable" value="true" />
<forward name="success" path="/question/querymyquestion.jsp" />
</action>
说的没错的花,连接中的"method"应该和parameter的值应该是一致的,而不是调用方法名