一定要注意:url中includeParams的属性的默认值是get,如果没有在struts.xml指定新的值,那么使用url标签引用的所有的静态文件都会带上通过get方法传递的参数值。另外:includeParams的属性值还有none、allall,是把get和post" />

struts2标签之url标签

系统 1670 0

下面是struts2标签的常用的用法
<s:url value="/images/copyright.jpg" />
<s:url action="list" namespace="/qxgl" />
一定要注意:url中includeParams的属性的默认值是get,如果没有在struts.xml指定新的值,那么使用url标签引用的所有的静态文件都会带上通过get方法传递的参数值。
另外:includeParams的属性值还有none、all
all,是把get和post中的参数加入到 url 参数中 ;
none是不把参数加入到url中;

例如:你在detail.jsp中写入

<link href="<s:url value="/css/styleqxgl.css"/>" rel="stylesheet"
type="text/css">

在浏览器中输入http://localhost/detail.jsp?id=5

<link href="/web应用名称/css/styleqxgl.css?id=5" rel="stylesheet"
type="text/css">
这样浏览器就又下载了一次styleqxgl.css,如果你的系统放在公网上,那么带宽的费用是很贵的,使用浏览器的缓存,可以有效的利用带宽,节约成本。

解决这个问题的办法有两个,一个是<s:url value="/css/styleqxgl.css" includeParams="none"/>

另外一个就是在struts.xml中配置,参考下文:

Setting a default value for includeParams

The property struts.url.includeParams can be used to set the default value of the includeParams attribute.

Setting the default value of includeParams
        
          <struts>
        
        
...
<constant name= "struts.url.includeParams" value= "none" />
...
</struts>

See Constant Configuration for further information.

Parameters

Name

Required

Default

Evaluated

Type

Description

action false
false String The action to generate the URL for, if not using value
anchor false
false String The anchor for this URL
encode false true false Boolean Whether to encode parameters
escapeAmp false true false Boolean Specifies whether to escape ampersand (&) to (&amp or not
forceAddSchemeHostAndPort false false false Boolean Specifies whether to force the addition of scheme, host and port or not
id false
false String Deprecated. Use 'var' instead
includeContext false true false Boolean Whether actual context should be included in URL
includeParams false get false String The includeParams attribute may have the value 'none', 'get' or 'all'
method false
false String The method of action to use
namespace false
false String The namespace to use
portletMode false
false String The resulting portlet mode
portletUrlType false
false String Specifies if this should be a portlet render or action URL. Default is "render". To create an action URL, use "action".
scheme false
false String Set scheme attribute
value false
false String The target value to use, if not using action
var false
false String Name used to reference the value pushed into the Value Stack
windowState false
false String The resulting portlet window state

struts2标签之url标签


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论