如何从超链接中捕获Struts中的EventDispatchAction?

发布于 2024-10-21 17:39:58 字数 1736 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-10-28 17:39:58

谢谢米格尔。实际上,问题不在于使用带有链接的操作,而在于捕获适当的事件。当用户单击任何搜索选项时,该事件将在 SearchApplicationAction 中处理。但是在对搜索结果进行分页之后,只要有人单击页码,我就必须生成这些操作。如果我对超链接中的操作进行硬编码,那么它就可以工作。

 <td><a href="searchApplication.do?nameSubmit&page=${emp}">${emp}</a></td>

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.

 <td><a href="searchApplication.do?nameSubmit&page=${emp}">${emp}</a></td>

梦里人 2024-10-28 17:39:58

您可以使用 struts taglib: 来构建与 struts 操作相关的链接。请参阅:http://struts.apache.org/ 1.x/struts-taglib/tagreference.html#html:link

You 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文