简体   繁体   English

如何在 Struts2 JSP 中使用全局转发(struts-config.xml)?

[英]How to use a global forward (struts-config.xml) in Struts2 JSP?

I am migrating a Struts1 web app to Struts2.我正在将 Struts1 Web 应用程序迁移到 Struts2。 I have the following in my struts-config.xml file:我的 struts-config.xml 文件中有以下内容:

<global-forwards >
    <forward name="css" path="/common/css/app-global.css" />
</global-forwards>

In my JSP today (Struts 1), I have this call:在我今天的 JSP(Struts 1)中,我有这样的电话:

<link rel="stylesheet" id="default" type="text/css" href="<html:rewrite forward='css'/>" />

What is the equivalent way to do this in the JSP in Struts 2?在 Struts 2 的 JSP 中执行此操作的等效方法是什么? I tried <s:url value="css"> but no luck.我试过<s:url value="css">但没有运气。

I just want to point to the reference in global-forwards.我只想指出 global-forwards 中的参考。 I'm sure it's something simple I'm overlooking.我敢肯定这是我忽略的一些简单的事情。

UPDATE: Listen, if there is a better way than using struts-config.xml (which I'm wondering if that should even be used in Struts 2), then by all means, set me straight.更新:听着,如果有比使用 struts-config.xml 更好的方法(我想知道它是否应该在 Struts 2 中使用),那么无论如何,让我直截了当。 I just didn't know if using the actual path was superior/inferior to using the specified forward name.我只是不知道使用实际路径是否优于/劣于使用指定的转发名称。

No need for some global forward mapping or whatever.不需要一些全局正向映射或其他什么。 Just use <s:url> tag with value attribute.只需使用带有value属性的<s:url>标签。

<link rel="stylesheet" id="default" type="text/css" 
      href="<s:url value='/common/css/app-global.css'/>" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM