我有一個帶有鏈接的JSP文件象下面這樣:通鏈接價值豆
<a href="links.do?method=homeAdmin">
<a href="links.do?method=signUp">
而且我有一個動作類LinkAction.java
:
public class LinkAction extends org.apache.struts.action.Action {
public ActionForward signUp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("signUp");
}
public ActionForward homeAdmin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("homeAdmin");
}
}
的問題是,這是行不通的。但是當我將其更改爲這樣的情況時,它僅適用於signUp
操作。
public class LinkAction extends org.apache.struts.action.Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("signUp");
}
}
我也試圖改變它
public class LinkAction extends DispatchAction { ... }
這裏是我的struts-config.xml
<action input="/index.jsp"
name="signUp"
path="/links"
scope="session"
type="Actions.LinkAction">
<forward name="signUp" path="/signUp.jsp"/>
<forward name="homeAdmin" path="/homeAdmin.jsp"/>
</action>
我想利用這個單一操作文件在我的網頁所有鏈接。我該怎麼做?
你可以在你的'struts-config.xml'中共享動作定義嗎? –
我認爲你只需要在'struts-config.xml'中添加一些東西,然後使用一個擴展類'org.apache.struts.actions.DispatchAction'的動作。 –