【问题标题】:Regular Expressions Struts 1.3 Action Mapping正则表达式 Struts 1.3 动作映射
【发布时间】:2018-12-02 17:27:40
【问题描述】:

据我所知,我正在使用 Struts 1.3 开发一个项目,因为它位于 struts-config-default.xml 文件的顶部:

<!DOCTYPE struts-config PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
    "http://struts.apache.org/dtds/struts-config_1_3.dtd">

有没有办法将通配符映射到一个jsp文件?我尝试了各种通配符变体:

<action path="/hello/candy" type="com.officedepot.globalweb.framework.action.ForwardDisplayAction">
        <forward name="success" path="/WEB-INF/jsp/candyStore.jsp" />
    </action>

我有一个在“candyStore.jsp”中加载的单页应用程序,所以我希望 /hello/candy 之后的所有 URI 都路由到同一个 JSP。 (例如www.site.com/hello/candy/pageOne、www.site.com/hello/candy/33/jellybean、www.site.com/hello/candy/test都应该转发到jsp candyStore)

这完全可能使用 Struts 1.3 还是我应该编写所有可能的路线:(

谢谢!

【问题讨论】:

    标签: java struts struts-1 struts-config action-mapping


    【解决方案1】:

    在您的操作文件中

    public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request , HttpServletResponse response) 
                throws Exception{
    
    
            //Perform any code here like error 404.
            return mapping.findForward("unspecified");
        }
    

    在你的配置文件中的struts动作路径中

    <forward name="unspecified" path="/candyStore.jsp"/>
    

    【讨论】:

    • 如果它不能解决你的意思,请评论,我会删除答案。由于答案很长,我无法在 cmets 中发帖。否则我会的。
    【解决方案2】:

    在 Google 上大约 30 秒:

    https://dzone.com/tutorials/java/struts/struts-example/struts-wildcards-in-action-mapping-example.html

    <action-mappings>
      <action path="/*Action" type="com.vaannila.reports.{1}Action" name="{1}Form">
        <forward name="success" path="/{1}.jsp" />
      </action>
    </action-mappings>
    

    您不需要在转发的path 中使用通配符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-19
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      相关资源
      最近更新 更多