如何从超链接中捕获Struts中的EventDispatchAction?
我有一个 JSP 页面,其中有多个搜索选项,即“按应用程序 ID 搜索”、“按申请人名称搜索”等。我使用 struts EventDispatchAction 来捕获特定提交按钮生成的事件。这工作正常。下面是 struts-config 文件的快照:
现在我在对搜索结果进行分页时遇到问题,因为单击页码时无法生成事件。它们是超链接。下面是用于生成页码的代码:
<c:forEach items="${pagelist}" var="emp">
<td><a href="#?page=${emp}">${emp}</a></td>
</c:forEach>
我不确定用什么来代替 # 来为 EventDispatchAction 生成事件。下面给出了捕获提交的 ActionClass:
public class SearchApplicationAction extends org.apache.struts.actions.EventDispatchAction {
public ActionForward idSubmit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String idText = searchApp.getAppId();
int appId = Integer.parseInt(idText);
UserManager manager = new UserManager();
applist = manager.ViewApplicationById(appId);
sess.setAttribute("applicationList", applist);
return mapping.findForward("idSubmit");
}
public ActionForward nameSubmit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String name = searchApp.getApplicantName();
UserManager manager = new UserManager();
applist = manager.ViewApplicationByName(name);
sess.setAttribute("applicationList", applist);
return mapping.findForward("nameSubmit");
}
}
这方面的任何帮助都会非常有帮助。谢谢
I have a JSP page where there are multiple options for search, i.e. "search by Application id", "search by Applicant name" etc. I have used struts EventDispatchAction to catch the event generated by a particular submit button. This is working fine. Below is the snap of the struts-config file for this:
Now I am facing problem in paginating the search results, because I am not able to generate event when the page numbers are clicked. They are hyperlinks. Below is the code used to generate the page numbers:
<c:forEach items="${pagelist}" var="emp">
<td><a href="#?page=${emp}">${emp}</a></td>
</c:forEach>
I am not sure what to put in place of # to generate event for EventDispatchAction. The ActionClass to capture the submits is given below:
public class SearchApplicationAction extends org.apache.struts.actions.EventDispatchAction {
public ActionForward idSubmit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String idText = searchApp.getAppId();
int appId = Integer.parseInt(idText);
UserManager manager = new UserManager();
applist = manager.ViewApplicationById(appId);
sess.setAttribute("applicationList", applist);
return mapping.findForward("idSubmit");
}
public ActionForward nameSubmit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String name = searchApp.getApplicantName();
UserManager manager = new UserManager();
applist = manager.ViewApplicationByName(name);
sess.setAttribute("applicationList", applist);
return mapping.findForward("nameSubmit");
}
}
Any help in this regard will be very helpful. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢米格尔。实际上,问题不在于使用带有链接的操作,而在于捕获适当的事件。当用户单击任何搜索选项时,该事件将在 SearchApplicationAction 中处理。但是在对搜索结果进行分页之后,只要有人单击页码,我就必须生成这些操作。如果我对超链接中的操作进行硬编码,那么它就可以工作。
Thanks Miguel. Actually the problem is not in using actions with links but to catch the appropriate event. When a user clicks on any of the search options then the event is handled in SearchApplicationAction. But after paginating the search results, I have to generate those actions whenever someone clicks on the page numbers. If I hardcode the action in hyperlink then it works.
您可以使用 struts taglib:
来构建与 struts 操作相关的链接。请参阅:http://struts.apache.org/ 1.x/struts-taglib/tagreference.html#html:linkYou could use the struts taglib:
<html:link>
in order to build links related to struts actions. See this: http://struts.apache.org/1.x/struts-taglib/tagreference.html#html:link