下面是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 (& |
| 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 标签的使用方法及其参数详解,特别关注 includeParams 属性如何避免静态资源加载时带上不必要的 GET 参数,提高网站性能。
260

被折叠的 条评论
为什么被折叠?



