Struts里面<html:link>的使用方法以及加多个参数的方法
2012-08-07 09:18
891 查看
最近在研究struts,里面碰到了<html:link>做个标签,就研究了一下他的用法。
首先介绍它的几个属性:
forward属性:链接到一个global forward上;
action属性:链接到一个action mapping上;
href属性:这个链接会转发给控制器,由控制器做决定;
page属性:一个相对的链接。
用page属性链接到action上:
<html:link page="/html-link.do">
Linking with the page attribute.
</html:link>
注意,上面的代码中你不必指定web的关联。相反的,如果你使用href属性,你就必须像下面所示指出web的关联(这里的关联就是struts-exercise):
<html:link href="/struts-exercise-taglib/html-link.do">
Using Href
</html:link>
很明显,当你在相同的web应用程序中做链接是,它比page属性更加好。你也能用href在不同的服务器上创建链接:
<html:link href="http://otherserver/strutsTut/html-link.do">
Using Href
</html:link>
另一种链接到html-link.do的方法是用action属性:
<html:link action="/html-link">
Using Action attribute
</html:link>
你也可以以硬编码的方式使用参数:
<html:link page="/htmllink.do?doubleProp=3.3&longProp=32">
Double and long via hard coded changes
</html:link>
或者使用paramId, paramName, and paramProperty属性:
<html:link page="/html-link.do" paramId="booleanProperty" paramName="testbean"
paramProperty="nested.booleanProperty">
Boolean via paramId, paramName, and paramValue
</html:link>
解析后的代码:
<a href="/struts-exercise-taglib/html-link.do?booleanProperty=false">
Boolean via paramId, paramName, and paramValue
</a>
另外,还能使用带name属性的Map来实现传递多个参数:
<%
java.util.HashMap newValues = new java.util.HashMap();
newValues.put("floatProperty", new Float(444.0));
newValues.put("intProperty", new Integer(555));
newValues.put("stringArray", new String[]
{ "Value 1", "Value 2", "Value 3" });
pageContext.setAttribute("newValues", newValues);
%>
...
<html:link action="/html-link" name="newValues">
Float, int, and stringArray via name (Map)
</html:link>
你也能够链接到Map类型的action上,上面的代码解析后的结果:
<html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer">
<tr><td><%= pageContext.getAttribute("msg") %></td></tr>
</html:messages>
参考文献:http://blog.sina.com.cn/s/blog_48f77adb0100050q.html
特记于此!以备勿忘!
首先介绍它的几个属性:
forward属性:链接到一个global forward上;
action属性:链接到一个action mapping上;
href属性:这个链接会转发给控制器,由控制器做决定;
page属性:一个相对的链接。
用page属性链接到action上:
<html:link page="/html-link.do">
Linking with the page attribute.
</html:link>
注意,上面的代码中你不必指定web的关联。相反的,如果你使用href属性,你就必须像下面所示指出web的关联(这里的关联就是struts-exercise):
<html:link href="/struts-exercise-taglib/html-link.do">
Using Href
</html:link>
很明显,当你在相同的web应用程序中做链接是,它比page属性更加好。你也能用href在不同的服务器上创建链接:
<html:link href="http://otherserver/strutsTut/html-link.do">
Using Href
</html:link>
另一种链接到html-link.do的方法是用action属性:
<html:link action="/html-link">
Using Action attribute
</html:link>
你也可以以硬编码的方式使用参数:
<html:link page="/htmllink.do?doubleProp=3.3&longProp=32">
Double and long via hard coded changes
</html:link>
或者使用paramId, paramName, and paramProperty属性:
<html:link page="/html-link.do" paramId="booleanProperty" paramName="testbean"
paramProperty="nested.booleanProperty">
Boolean via paramId, paramName, and paramValue
</html:link>
解析后的代码:
<a href="/struts-exercise-taglib/html-link.do?booleanProperty=false">
Boolean via paramId, paramName, and paramValue
</a>
另外,还能使用带name属性的Map来实现传递多个参数:
<%
java.util.HashMap newValues = new java.util.HashMap();
newValues.put("floatProperty", new Float(444.0));
newValues.put("intProperty", new Integer(555));
newValues.put("stringArray", new String[]
{ "Value 1", "Value 2", "Value 3" });
pageContext.setAttribute("newValues", newValues);
%>
...
<html:link action="/html-link" name="newValues">
Float, int, and stringArray via name (Map)
</html:link>
你也能够链接到Map类型的action上,上面的代码解析后的结果:
<html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer">
<tr><td><%= pageContext.getAttribute("msg") %></td></tr>
</html:messages>
参考文献:http://blog.sina.com.cn/s/blog_48f77adb0100050q.html
特记于此!以备勿忘!
相关文章推荐
- HTML中让图片滚动的<marquee>标签的使用方法
- 使用html <a href=""/>标签连接action的方法
- C#中Queue<T>类的使用以及部分方法的源代码分析
- <html:optionsCollection />标签与LabelValueBean使用方法
- HTML中<input>参数,以及文本输入框,文本域的讲解
- eclipse Maven配置以及使用方法<转>
- struts中<html:radio>标签默认选中的解决方法《转载》
- 使用<a>标签调用struts2的action、传递动态参数、以及参数中出现加号等特殊字符的处理方法
- 在JS里面,取struts的<html:form>标签里面的<html:text property="title"/>值
- struts与jsp <s:iterator>使用方法
- C#中Queue<T>类的使用以及部分方法的源码分析
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数出错“应输入 2 个参数,却提供了 3 个)
- Java笔记3 多线程<2>线程间通信-代码分析以及多线程常见方法的运用
- 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/>
- 使用<a>标签提交action会执行两次后台方法的原因(反射机制小实例问题的解决)
- C++ 中dynamic_cast<>的使用方法
- <Android 开源库> GreenDAO 使用方法具体解释<译文>
- 有关Struts标签<html:cancel>使用的一点提示
- HTML <frameset> 标签使用
- HTML<marquee>标签的详细使用介绍