<i id='TwNUx'><tr id='TwNUx'><dt id='TwNUx'><q id='TwNUx'><span id='TwNUx'><b id='TwNUx'><form id='TwNUx'><ins id='TwNUx'></ins><ul id='TwNUx'></ul><sub id='TwNUx'></sub></form><legend id='TwNUx'></legend><bdo id='TwNUx'><pre id='TwNUx'><center id='TwNUx'></center></pre></bdo></b><th id='TwNUx'></th></span></q></dt></tr></i><div id='TwNUx'><tfoot id='TwNUx'></tfoot><dl id='TwNUx'><fieldset id='TwNUx'></fieldset></dl></div>

  1. <small id='TwNUx'></small><noframes id='TwNUx'>

    <legend id='TwNUx'><style id='TwNUx'><dir id='TwNUx'><q id='TwNUx'></q></dir></style></legend>
      • <bdo id='TwNUx'></bdo><ul id='TwNUx'></ul>
    1. <tfoot id='TwNUx'></tfoot>
    2. 如何使用 Struts2 更改默认 JSP/模板位置

      时间:2023-10-14
      <legend id='UCZ7M'><style id='UCZ7M'><dir id='UCZ7M'><q id='UCZ7M'></q></dir></style></legend>
        <bdo id='UCZ7M'></bdo><ul id='UCZ7M'></ul>

        • <i id='UCZ7M'><tr id='UCZ7M'><dt id='UCZ7M'><q id='UCZ7M'><span id='UCZ7M'><b id='UCZ7M'><form id='UCZ7M'><ins id='UCZ7M'></ins><ul id='UCZ7M'></ul><sub id='UCZ7M'></sub></form><legend id='UCZ7M'></legend><bdo id='UCZ7M'><pre id='UCZ7M'><center id='UCZ7M'></center></pre></bdo></b><th id='UCZ7M'></th></span></q></dt></tr></i><div id='UCZ7M'><tfoot id='UCZ7M'></tfoot><dl id='UCZ7M'><fieldset id='UCZ7M'></fieldset></dl></div>
        • <small id='UCZ7M'></small><noframes id='UCZ7M'>

              <tbody id='UCZ7M'></tbody>

                <tfoot id='UCZ7M'></tfoot>
              • 本文介绍了如何使用 Struts2 更改默认 JSP/模板位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在开发一个在 Eclipse 中使用 Struts2 的新 Java EE 应用程序.我想将 JSP 文件保存在源文件夹 (src/main/jsp) 中,而不是 WebContent 中.部署后,所有源文件都会复制到 WebContent/WEB-INF/classes.这还具有使 jsp 文件无法直接访问的额外效果(我希望所有内容都需要操作干预).这意味着要显示结果,我必须这样做:

                I'm working on a new Java EE application that uses Struts2 in Eclipse. I want to keep the JSP files in the source folder (src/main/jsp) and not in WebContent. When deployed, the all source files get copied over to WebContent/WEB-INF/classes. This also has the bonus effect of making the jsp files inaccessible directly (I want everything to require action intervention). This means that to make results display, I have to do this:

                <result name="SUCCESS">WEB-INF/classes/index.jsp</result>
                

                是否可以设置 jsp 文件的默认位置,以便仅 index.jsp 就足以引用它们?理想情况下,这些文件也将位于 WEB-INF/jsp 中,并且不会与类混在一起.

                Is it possible to set the default location of the jsp files so that just index.jsp is sufficient to reference them? Ideally the files would also sit in WEB-INF/jsp and not get mixed with the classes.

                我看到 spring 有这个功能.我希望 Struts2 也能做到这一点.

                I saw that spring has this feature. I'm hoping for the same thing for Struts2.

                推荐答案

                可以创建一个常量配置参数,例如

                You can create a constant configuration parameter, e.g.

                <constant name="struts.result.path" value="/WEB-INF/classes" />
                

                然后将此常量注入到自定义 dispatcher 结果中.将此添加到您的默认包中:

                Then inject this constant into custom dispatcher result. Add this to your default package:

                <result-types>
                    <result-type name="dispatcher" default="true" class="struts.results.MyServletDispatcherResult" />
                </result-types>
                

                实现很简单,只需在配置结果的位置添加前缀即可.

                The implementation is easy, you just add a prefix to the location of the result when it's configured.

                public class MyServletDispatcherResult extends ServletDispatcherResult {
                
                    private String resultPath;
                
                    public String getResultPath() {
                        return resultPath;
                    }
                
                    @Inject(value = "struts.result.path", required = false)
                    public void setResultPath(String resultPath) {
                        this.resultPath = resultPath;
                    }
                
                    @Override
                    public void setLocation(String location) {
                        super.setLocation(resultPath+location);
                    }
                
                    public MyServletDispatcherResult() {
                        super();
                    }
                
                //    @Inject
                //    public MyServletDispatcherResult(String location) {
                //
                //        super(resultPath+location);
                //    }
                }
                

                然后你可以在结果中使用普通位置,例如

                Then you can use ordinary locations in the results, e.g.

                <result name="SUCCESS">/index.jsp</result> 
                

                这篇关于如何使用 Struts2 更改默认 JSP/模板位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:没有身份验证信任证书的 JavaMail SSL 下一篇:升级到 struts 2.3.15.1 不会在操作类上设置 HashMap 值

                相关文章

              • <small id='6Wew5'></small><noframes id='6Wew5'>

                <legend id='6Wew5'><style id='6Wew5'><dir id='6Wew5'><q id='6Wew5'></q></dir></style></legend>

                <i id='6Wew5'><tr id='6Wew5'><dt id='6Wew5'><q id='6Wew5'><span id='6Wew5'><b id='6Wew5'><form id='6Wew5'><ins id='6Wew5'></ins><ul id='6Wew5'></ul><sub id='6Wew5'></sub></form><legend id='6Wew5'></legend><bdo id='6Wew5'><pre id='6Wew5'><center id='6Wew5'></center></pre></bdo></b><th id='6Wew5'></th></span></q></dt></tr></i><div id='6Wew5'><tfoot id='6Wew5'></tfoot><dl id='6Wew5'><fieldset id='6Wew5'></fieldset></dl></div>
                1. <tfoot id='6Wew5'></tfoot>
                    <bdo id='6Wew5'></bdo><ul id='6Wew5'></ul>