Struts标签:
TestTagsAction.java:
package com.oristand.actions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.opensymphony.xwork2.ActionSupport;
public class TestTagsAction extends ActionSupport {
private String username;
private String password;
public TestTagsAction() {
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
}
浏览器访问:http://localhost:8888/struts2_0100_OGNL/tags.action?username=u&password=p
Struts.xml:
<action name="tags" class="com.oristand.actions.TestTagsAction">
<result>/tags.jsp</result>
</action>
Tags.jsp:
1:<s:property>标签
<li>【value="username" is:】 <s:property value="username"/></li>//输出结果为u,当作对象处理,ognl
<li>【value="'username'" is: 】<s:property value="'username'"/></li>//
输出结果为username,当作字符串处理
<li>【value="admin" default="管理员"】 <s:property value="admin" default="管理员"/></li>
<li>【解析html标签 escape默认情况】<s:property value="'<hr/>'"/></li>//输出结果为<hr/>,默认是解析
<li>【解析html标签 escape=false】<s:property value="'<hr/>'" escape="false"/></li>//输出结果为一条横线,未解析
2:<s:set/>标签
一:
: 1:set标签的使用,set标签声明的变量的的范围默认是(request和ActionContext),如【var="adminName" value="username"】<br/>
<s:set var="adminName" value="username"></s:set>
<li>从request取值【value="#request.adminName"】:<s:property value="#request.adminName"/></li>
<li>从ActionContext取值【value="#adminName"】:<s:property value="#adminName"/></li>
<li>从session取值【value="#session.adminName"】:<s:property value="#session.adminName"/></li>
<li>从application取值【value="#application.adminName"】:<s:property value="#application.adminName"/></li><br/>
<br/>
这个运行的结果是(浏览器上):
· 1:set标签的使用,set标签声明的变量的的范围默认是(request和ActionContext),如【var="adminName" value="username"】
· 从request取值【value="#request.adminName"】:user
· 从ActionContext取值【value="#adminName"】:user
· 从session取值【value="#session.adminName"】:
· 从application取值【value="#application.adminName"】:
二:
2:指定set标签声明的变量的的范围,如【var="adminPassword1" value="password" scope="<font color="red">page</font>"】<br/>
<s:set var="adminPassword1" value="password" scope="page"></s:set>
<li>【从page中取值,pageContext.getAttribute("adminPassword1")】<%=pageContext.getAttribute("adminPassword1") %></li>
<li>【从request中取值,value="#request.adminPassword1"】<s:property value="#request.adminPassword1"/></li>
<li>【从session中取值,value="#request.adminPassword1"】<s:property value="#session.adminPassword1"/></li>
<li>【从application中取值,value="#application.adminPassword1"】<s:property value="#application.adminPassword1"/></li><br/><br/>
这个运行的结果是(浏览器上):
· 2:指定set标签声明的变量的的范围,如【var="adminPassword1" value="password" scope="page"】
· 【从page中取值,pageContext.getAttribute("adminPassword1")】pass
· 【从request中取值,value="#request.adminPassword1"】
· 【从session中取值,value="#request.adminPassword1"】
· 【从application中取值,value="#application.adminPassword1"】
三:
指定set标签声明的变量的的范围,如【var="adminPassword2" value="password" scope="<font color="red">request</font>"】<br/>
<s:set var="adminPassword2" value="password" scope="request"></s:set>
<li>【从page中取值,pageContext.getAttribute("adminPassword2")】<%=pageContext.getAttribute("adminPassword2") %></li>
<li>【从request中取值,value="#request.adminPassword2"】<s:property value="#request.adminPassword2"/></li>
<li>【从session中取值,value="#request.adminPassword2"】<s:property value=Cou