Struts (Java),更改采用输入参数=页面的操作的前向名称不允许我以新名称访问该页面

发布于 2024-11-29 13:50:10 字数 2046 浏览 0 评论 0原文

我对 Struts 还很陌生(对于当前雇主的遗留项目),在本例中我使用的是 Struts 1,所以不确定这是否重要。

我正在尝试编辑一个包含大量前锋的动作,但为了简单起见,我只包含了一个。该特定转发仅映射到静态 JSP,通常无需登录应用程序即可访问。

因此,通常可以在以下位置访问此页面(假设我在本地运行此页面):

https://localhost/sc.do?page=download

转发设置为:

<forward name="download" path=".downloadPage"/>

现在我尝试做的就是将名称 download 更改为其他名称(在下面的转发中),例如 downloadtest,我确保重建它等并重新启动,现在我无法在

https://localhost/sc.do?page=download 访问它,但也没有我可以访问该页面吗: https://localhost/sc.do?page=downloadtest

我真的很困惑配置文件中还有什么会阻止它工作,我一直在阅读教程和我的理解这应该有效。非常感谢任何建议。

      <action path="/sc"
              type="com.somecompany.wa.actions.PageDispatchAction"
              name="scAdminForm"
              parameter="page">

        <set-property property="secure" value="true"/>

        <forward name="downloadtest" path=".downloadPage"/>
</action>

这是 com.somecompany.wa.actions.PageDispatchAction 类:

public class PageDispatchAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ActionContext context = new ActionContext(mapping, form, request, response);
        Command command = new CheckPageSecurityCommand();
        boolean stop = command.execute(context);
        if (stop) {
            return null;
        } else {
            return (ActionForward) context.get("forward");
        }
    }

    // redirects control to logout page
    // calls to this method should be followed by return null or end of method.
    protected void redirectToLogout(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletWebContext context = new ServletWebContext(request.getSession(true).getServletContext(), request, response);
        Command command = new RedirectToLogoutCommand();
        command.execute(context);
    }
}

I'm still fairly new to Struts (for a legacy project for current employer), in this case I am using Struts 1 so not sure if that matters.

I am trying to edit an action that has a bunch of forwards but for simplicity I have just included one. This particular forward just maps to a static JSP and can normally be accessed without having to login to the application.

So normally this page is accessed at (assuming I'm running this locally):

https://localhost/sc.do?page=download

The forward is set as:

<forward name="download" path=".downloadPage"/>

Now all I tried doing was changing the name download to something else (in the forward below), such as downloadtest, I made sure to rebuild it, etc and relaunched, now I cannot access it at

https://localhost/sc.do?page=download but neither can I access the page at: https://localhost/sc.do?page=downloadtest

I'm really confused as to what else there would be in a configuration file that would prevent this from working, I have been reading tutorials and from my understanding this should work. Any advice is greatly appreciated.

      <action path="/sc"
              type="com.somecompany.wa.actions.PageDispatchAction"
              name="scAdminForm"
              parameter="page">

        <set-property property="secure" value="true"/>

        <forward name="downloadtest" path=".downloadPage"/>
</action>

This is the com.somecompany.wa.actions.PageDispatchAction class:

public class PageDispatchAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ActionContext context = new ActionContext(mapping, form, request, response);
        Command command = new CheckPageSecurityCommand();
        boolean stop = command.execute(context);
        if (stop) {
            return null;
        } else {
            return (ActionForward) context.get("forward");
        }
    }

    // redirects control to logout page
    // calls to this method should be followed by return null or end of method.
    protected void redirectToLogout(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletWebContext context = new ServletWebContext(request.getSession(true).getServletContext(), request, response);
        Command command = new RedirectToLogoutCommand();
        command.execute(context);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

鸠书 2024-12-06 13:50:10

我更熟悉 Struts 1.2,这里看起来像 Struts 1.3,但我惊讶地发现 PageDispatchAction 没有扩展 DispatchAction 而不是 行动。通常,当您在 struts-config.xml 中定义 actionparameter 属性时,type 指的是DispatchAction 的子类。这表明请求中提供的任何 page 值都将按照此处定义的方式映射到同名操作中的方法。因此,page=download 将映射到 PageDispatchAction 中的 download 方法。不管怎样,我不确定你这里的内容是如何工作的,因为在我看来,返回似乎正在寻找一个名为 forwardActionForward 。也许这是我对 Struts 1.2 的偏见,而 1.3 的工作方式有所不同。没有把握。

I'm more familiar with Struts 1.2 and what you have here looks like Struts 1.3, but I was surprised to see that PageDispatchAction didn't extend DispatchAction instead of Action. Typically, when you define the parameter attribute of an action in struts-config.xml the type refers to a subclass of DispatchAction. This indicates that whatever value for page is supplied in the request would map to a method in the action of the same name with the way things are defined here. So page=download would map to a download method in PageDispatchAction. Anyway, I'm not sure how what you have here is working since to my eye it looks like the return is looking for an ActionForward called forward. Perhaps it is my Struts 1.2 bias though and 1.3 works differently. Not sure.

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