struts2 ognl 标签输出

public class TestAction extends BaseAction {

	private String testAttr;
	private Map attrMap;

	public Map getAttrMap() {
		return attrMap;
	}

	public void setAttrMap(Map attrMap) {
		this.attrMap = attrMap;
	}

	public String test() {
		testAttr = "测试";
		
		attrMap = new HashMap();
		attrMap.put("attr", "属性map");
		
		Map requestMap = new HashMap();
		requestMap.put("req_", "测试request设值");
		
		HttpServletRequest request222 = ServletActionContext.getRequest();
		request222.setAttribute("requestMap", requestMap);
		request222.setAttribute("requestSet", "request设置单个值");

		CommonsVObj v = new CommonsVObj();
		v.setId("IDDDDDDDDDD");
		v.setName("NameNNNNNNN");
		ActionContext.getContext().put("objVVV", v);
		
		CommonsVObj v3 = new CommonsVObj();
		v3.setId("ID33333");
		v3.setName("Name333333");
		request222.setAttribute("objVVV333", v3);

		Map contextMap = new HashMap();
		contextMap.put("cont", "context测试");
		ActionContext.getContext().put("contextMap", contextMap);
		ActionContext.getContext().put("contextSet", "单个cont");
		

		return "success";
	}

	public String getTestAttr() {
		return testAttr;
	}

	public void setTestAttr(String testAttr) {
		this.testAttr = testAttr;
	}

}
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>栏目列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>
<body>
<%  
          request.setAttribute("req", "request scope");  
           request.getSession().setAttribute("sess", "session scope");  
           request.getSession().getServletContext().setAttribute("app",                 "aplication scope");  
        %> 

	<br />
		<hr>
	el表达式:<br>
	testAttr:${testAttr}<br>
	requestSet:${requestSet}<br>
	requestMap:${requestMap}<br>
	requestMap.req_:${requestMap.req_}<br>
	attrMap:${attrMap}<br>
	attrMap.attr:${attrMap.attr}<br>
	<hr>
	struts2 ongl表达式:<br>
	<s:form action="/test/upLoad_test.do" method="post"
		enctype="multipart/form-data">
		<s:hidden name="t101" value="testAttr"></s:hidden><!-- no -->
		<s:hidden name="t102" value="requestSet"></s:hidden><!-- no -->
		<s:hidden name="t103" value="requestMap"></s:hidden><!-- no -->
		<s:hidden name="t104" value="requestMap.req_"></s:hidden><!-- no -->
		<s:hidden name="t105" value="attrMap"></s:hidden><!-- no -->
		<s:hidden name="t106" value="attrMap.attr"></s:hidden><!-- no -->
		
		<s:hidden name="t201" value="%{testAttr}"></s:hidden><!-- ok -->
		<s:hidden name="t202" value="%{requestSet}"></s:hidden><!-- no -->
		<s:hidden name="t203" value="%{requestMap}"></s:hidden><!-- no -->
		<s:hidden name="t204" value="%{requestMap.req_}"></s:hidden><!-- no -->
		<s:hidden name="t205" value="%{attrMap}"></s:hidden><!-- ok -->
		<s:hidden name="t206" value="%{attrMap.attr}"></s:hidden><!-- ok -->
		
		<s:hidden name="t301" value="%{request.testAttr}"></s:hidden><!-- no -->
		<s:hidden name="t302" value="%{request.requestSet}"></s:hidden><!-- no -->
		<s:hidden name="t303" value="%{request.requestMap}"></s:hidden><!-- no -->
		<s:hidden name="t304" value="%{request.requestMap.req_}"></s:hidden><!-- no -->
		<s:hidden name="t305" value="%{request.attrMap}"></s:hidden><!-- no -->
		<s:hidden name="t306" value="%{request.attrMap.attr}"></s:hidden><!-- no -->
		
		<s:hidden name="t401" value="#testAttr"></s:hidden><!-- no -->
		<s:hidden name="t402" value="#requestSet"></s:hidden><!-- no -->
		<s:hidden name="t403" value="#requestMap"></s:hidden><!-- no -->
		<s:hidden name="t404" value="#requestMap.req_"></s:hidden><!-- no -->
		<s:hidden name="t405" value="#attrMap"></s:hidden><!-- no -->
		<s:hidden name="t406" value="#attrMap.attr"></s:hidden><!-- no -->
		
		
		<s:hidden name="t401" value="#request.testAttr"></s:hidden><!-- no -->
		<s:hidden name="t402" value="#request.requestSet"></s:hidden><!-- no -->
		<s:hidden name="t403" value="#request.requestMap"></s:hidden><!-- no -->
		<s:hidden name="t404" value="#request.requestMap.req_"></s:hidden><!-- no -->
		<s:hidden name="t405" value="#request.attrMap"></s:hidden><!-- no -->
		<s:hidden name="t406" value="#request.attrMap.attr"></s:hidden><!-- no -->
		
		<!-- context -->
		<s:hidden name="t501" value="contextSet"></s:hidden><!-- no -->
		<s:hidden name="t502" value="contextMap"></s:hidden><!-- no -->
		
		<s:hidden name="t601" value="%{contextSet}"></s:hidden><!-- ok -->
		<s:hidden name="t602" value="%{contextMap}"></s:hidden><!-- ok -->
		<s:hidden name="t603" value="%{contextMap.cont}"></s:hidden><!-- no -->
		<s:hidden name="t604" value="%{contextMap[cont]}"></s:hidden><!-- no -->
		
		<s:hidden name="t701" value="#contextSet"></s:hidden><!-- no -->
		<s:hidden name="t702" value="#contextMap"></s:hidden><!-- no -->
		<s:hidden name="t703" value="#contextMap[cont]"></s:hidden><!-- no -->
		<s:hidden name="t704" value="#contextMap.cont"></s:hidden><!-- no -->
		
		
		<s:hidden name="t801" value="objVVV"></s:hidden><!-- no -->
		<s:hidden name="t802" value="%{objVVV}"></s:hidden><!-- ok -->
		<s:hidden name="t803" value="%{objVVV.name}"></s:hidden><!-- no -->
		
		<s:hidden name="t901" value="objVVV333"></s:hidden><!-- no -->
		<s:hidden name="t902" value="%{objVVV333}"></s:hidden><!-- no -->
		<s:hidden name="t903" value="%{objVVV333.name}"></s:hidden><!-- no -->
		
		<s:hidden name="t1001" value="objVVV333"></s:hidden><!-- no -->
		<s:hidden name="t1002" value="%{request.objVVV333}"></s:hidden><!-- no -->
		<s:hidden name="t1003" value="%{request.objVVV333.name}"></s:hidden><!-- no -->
		
		<s:hidden name="t1101" value="#objVVV333"></s:hidden><!-- no -->
		<s:hidden name="t1102" value="#objVVV333.name"></s:hidden><!-- no -->
		
		<s:hidden name="t1201" value="#request.objVVV333"></s:hidden><!-- no -->
		<s:hidden name="t1202" value="#request.objVVV333.name"></s:hidden><!-- no -->
		
	</s:form>
			
		#testAttr:<s:property value="#testAttr"/><br><!-- no -->
		#requestSet:<s:property value="#requestSet"/><br><!-- no -->
		#request.testAttr:<s:property value="#request.testAttr"/><br><!-- ok -->
		#request.requestSet:<s:property value="#request.requestSet"/><br><br><!-- ok -->
		#request.requestMap:<s:property value="#request.requestMap"/><br><br><!-- ok -->
		#request.requestMap.req_:<s:property value="#request.requestMap.req_"/><br><br><!-- ok -->
		#request.attrMap:<s:property value="#request.attrMap"/><br><br><!-- ok -->
		#request.attrMap.attr:<s:property value="#request.attrMap.attr"/><br><br><!-- ok -->
		#contextSet:<s:property value="#contextSet"/><br><!-- ok -->
		#contextMap:<s:property value="#contextMap"/><br><br><!-- ok -->
		#request.contextSet:<s:property value="#request.contextSet"/><br><!-- ok -->
		#request.contextMap:<s:property value="#request.contextMap"/><br><br><!-- ok -->
		#request.contextMap.cont:<s:property value="#request.contextMap.cont"/><br><br><!-- ok -->
		#objVVV:<s:property value="#objVVV"/><br><br><!-- ok -->
		#objVVV.name:<s:property value="#objVVV.name"/><br><br><!-- ok -->
		#objVVV333:<s:property value="#objVVV333"/><br><br><!-- no -->
		#objVVV333.name:<s:property value="#objVVV333.name"/><br><br><!-- no -->
		#request.objVVV333:<s:property value="#request.objVVV333"/><br><br><!-- ok -->
		#request.objVVV333.name:<s:property value="#request.objVVV333.name"/><br><br><!-- ok -->
	
	<hr>
	
	<s:form action="/test/upLoad_test.do" method="post"
		enctype="multipart/form-data">
		<s:hidden name="testId" value="testAttr"></s:hidden>
		<s:hidden name="testId2" value="%{testAttr}"></s:hidden>
		<s:hidden name="testId3" value="#testMap.testAttr2"></s:hidden>
		<s:hidden name="testId4" value="#request.testMap.testAttr2"></s:hidden>
		<s:hidden name="testId5" value="%{testMap.testAttr2}"></s:hidden>
		<s:hidden name="testId6" value="%{request.testMap.testAttr2}"></s:hidden>
		<s:hidden name="testId7" value="%{requestScope.testMap.testAttr2}"></s:hidden>
		
		<s:hidden name="attr_1" value="attrMap"></s:hidden>
		<s:hidden name="attr_2" value="%{attrMap}"></s:hidden>
		<s:hidden name="attr_3" value="%{attrMap.attr}"></s:hidden>
		<s:hidden name="attr_4" value="#attrMap.attr"></s:hidden>
		
		
		<s:hidden name="req_1" value="#req"></s:hidden><br>
		<s:hidden name="req_2" value="#request.req"></s:hidden><br>
		<s:hidden name="req_3" value="%{req}"></s:hidden><br>
		
		#request.req:<s:property value="#request.req"/> <br>
		#testMap.testAttr2:<s:property value="#testMap.testAttr2"/> <br>
		#request.testMap.testAttr2:<s:property value="#request.testMap.testAttr2"/> <br>
		
		
		<s:file name="upload" label="输入要上传的文件名" />
	</s:form>
	有-request:<s:property value="#request.testMap.testAttr2"/><br>
	没有-request:<s:property value="#testMap.testAttr2"/><br>
	<br>
	el<br>
	${testMap}
	${testMap.testAttr2}
	
	
	

</body>
</html>
 

	<br />
		<hr>
	el表达式:<br>
	testAttr:测试<br>
	requestSet:request设置单个值<br>
	requestMap:{req_=测试request设值}<br>
	requestMap.req_:测试request设值<br>
	attrMap:{attr=属性map}<br>
	attrMap.attr:属性map<br>
	<hr>
	struts2 ongl表达式:<br>
				
<form id="upLoad_test" onsubmit="return true;" action="/test/upLoad_test.do" method="post" enctype="multipart/form-data"><table class="wwFormTable">
		<input type="hidden" name="t101" value="testAttr" id="upLoad_test_t101"/><!-- no -->
		<input type="hidden" name="t102" value="requestSet" id="upLoad_test_t102"/><!-- no -->
		<input type="hidden" name="t103" value="requestMap" id="upLoad_test_t103"/><!-- no -->
		<input type="hidden" name="t104" value="requestMap.req_" id="upLoad_test_t104"/><!-- no -->
		<input type="hidden" name="t105" value="attrMap" id="upLoad_test_t105"/><!-- no -->
		<input type="hidden" name="t106" value="attrMap.attr" id="upLoad_test_t106"/><!-- no -->
		
		<input type="hidden" name="t201" value="测试" id="upLoad_test_t201"/><!-- ok -->
		<input type="hidden" name="t202" value="" id="upLoad_test_t202"/><!-- no -->
		<input type="hidden" name="t203" value="" id="upLoad_test_t203"/><!-- no -->
		<input type="hidden" name="t204" value="" id="upLoad_test_t204"/><!-- no -->
		<input type="hidden" name="t205" value="{attr=属性map}" id="upLoad_test_t205"/><!-- ok -->
		<input type="hidden" name="t206" value="属性map" id="upLoad_test_t206"/><!-- ok -->
		
		<input type="hidden" name="t301" value="" id="upLoad_test_t301"/><!-- no -->
		<input type="hidden" name="t302" value="" id="upLoad_test_t302"/><!-- no -->
		<input type="hidden" name="t303" value="" id="upLoad_test_t303"/><!-- no -->
		<input type="hidden" name="t304" value="" id="upLoad_test_t304"/><!-- no -->
		<input type="hidden" name="t305" value="" id="upLoad_test_t305"/><!-- no -->
		<input type="hidden" name="t306" value="" id="upLoad_test_t306"/><!-- no -->
		
		<input type="hidden" name="t401" value="#testAttr" id="upLoad_test_t401"/><!-- no -->
		<input type="hidden" name="t402" value="#requestSet" id="upLoad_test_t402"/><!-- no -->
		<input type="hidden" name="t403" value="#requestMap" id="upLoad_test_t403"/><!-- no -->
		<input type="hidden" name="t404" value="#requestMap.req_" id="upLoad_test_t404"/><!-- no -->
		<input type="hidden" name="t405" value="#attrMap" id="upLoad_test_t405"/><!-- no -->
		<input type="hidden" name="t406" value="#attrMap.attr" id="upLoad_test_t406"/><!-- no -->
		
		
		<input type="hidden" name="t401" value="#request.testAttr" id="upLoad_test_t401"/><!-- no -->
		<input type="hidden" name="t402" value="#request.requestSet" id="upLoad_test_t402"/><!-- no -->
		<input type="hidden" name="t403" value="#request.requestMap" id="upLoad_test_t403"/><!-- no -->
		<input type="hidden" name="t404" value="#request.requestMap.req_" id="upLoad_test_t404"/><!-- no -->
		<input type="hidden" name="t405" value="#request.attrMap" id="upLoad_test_t405"/><!-- no -->
		<input type="hidden" name="t406" value="#request.attrMap.attr" id="upLoad_test_t406"/><!-- no -->
		
		<!-- context -->
		<input type="hidden" name="t501" value="contextSet" id="upLoad_test_t501"/><!-- no -->
		<input type="hidden" name="t502" value="contextMap" id="upLoad_test_t502"/><!-- no -->
		
		<input type="hidden" name="t601" value="单个cont" id="upLoad_test_t601"/><!-- ok -->
		<input type="hidden" name="t602" value="{cont=context测试}" id="upLoad_test_t602"/><!-- ok -->
		<input type="hidden" name="t603" value="" id="upLoad_test_t603"/><!-- no -->
		<input type="hidden" name="t604" value="" id="upLoad_test_t604"/><!-- no -->
		
		<input type="hidden" name="t701" value="#contextSet" id="upLoad_test_t701"/><!-- no -->
		<input type="hidden" name="t702" value="#contextMap" id="upLoad_test_t702"/><!-- no -->
		<input type="hidden" name="t703" value="#contextMap[cont]" id="upLoad_test_t703"/><!-- no -->
		<input type="hidden" name="t704" value="#contextMap.cont" id="upLoad_test_t704"/><!-- no -->
		
		
		<input type="hidden" name="t801" value="objVVV" id="upLoad_test_t801"/><!-- no -->
		<input type="hidden" name="t802" value="com.junbao.base.vo.CommonsVObj@471327" id="upLoad_test_t802"/><!-- ok -->
		<input type="hidden" name="t803" value="" id="upLoad_test_t803"/><!-- no -->
		
		<input type="hidden" name="t901" value="objVVV333" id="upLoad_test_t901"/><!-- no -->
		<input type="hidden" name="t902" value="" id="upLoad_test_t902"/><!-- no -->
		<input type="hidden" name="t903" value="" id="upLoad_test_t903"/><!-- no -->
		
		<input type="hidden" name="t1001" value="objVVV333" id="upLoad_test_t1001"/><!-- no -->
		<input type="hidden" name="t1002" value="" id="upLoad_test_t1002"/><!-- no -->
		<input type="hidden" name="t1003" value="" id="upLoad_test_t1003"/><!-- no -->
		
		<input type="hidden" name="t1101" value="#objVVV333" id="upLoad_test_t1101"/><!-- no -->
		<input type="hidden" name="t1102" value="#objVVV333.name" id="upLoad_test_t1102"/><!-- no -->
		
		<input type="hidden" name="t1201" value="#request.objVVV333" id="upLoad_test_t1201"/><!-- no -->
		<input type="hidden" name="t1202" value="#request.objVVV333.name" id="upLoad_test_t1202"/><!-- no -->
		
	</table></form>




			
		#testAttr:<br><!-- no -->
		#requestSet:<br><!-- no -->
		#request.testAttr:测试<br><!-- ok -->
		#request.requestSet:request设置单个值<br><br><!-- ok -->
		#request.requestMap:{req_=测试request设值}<br><br><!-- ok -->
		#request.requestMap.req_:测试request设值<br><br><!-- ok -->
		#request.attrMap:{attr=属性map}<br><br><!-- ok -->
		#request.attrMap.attr:属性map<br><br><!-- ok -->
		#contextSet:单个cont<br><!-- ok -->
		#contextMap:{cont=context测试}<br><br><!-- ok -->
		#request.contextSet:单个cont<br><!-- ok -->
		#request.contextMap:{cont=context测试}<br><br><!-- ok -->
		#request.contextMap.cont:context测试<br><br><!-- ok -->
		#objVVV:com.junbao.base.vo.CommonsVObj@471327<br><br><!-- ok -->
		#objVVV.name:NameNNNNNNN<br><br><!-- ok -->
		#objVVV333:<br><br><!-- no -->
		#objVVV333.name:<br><br><!-- no -->
		#request.objVVV333:com.junbao.base.vo.CommonsVObj@b56a28<br><br><!-- ok -->
		#request.objVVV333.name:Name333333<br><br><!-- ok -->
	
	<hr>

 

 

结果疑问就是:

 

<s:hidden name="t601" value="%{contextSet}"></s:hidden><!-- ok -->
<s:hidden name="t602" value="%{contextMap}"></s:hidden><!-- ok -->
<s:hidden name="t603" value="%{contextMap.cont}"></s:hidden><!-- no -->
<s:hidden name="t604" value="%{contextMap[cont]}"></s:hidden><!-- no -->

 

<s:hidden name="t901" value="objVVV333"></s:hidden><!-- no -->
<s:hidden name="t902" value="%{objVVV333}"></s:hidden><!-- no -->
<s:hidden name="t903" value="%{objVVV333.name}"></s:hidden><!-- no -->

 

几个为 no的标签中的值怎么输出????????????

 

 

 

 

<%--
<s:hidden name="t1301" value="${requestScope.requestSet}"></s:hidden>
--%>
<s:hidden name="t1401" value="%{#requestScope.requestSet}"></s:hidden><!-- no -->
<s:hidden name="t1402" value="%{#request.requestSet}"></s:hidden><!-- ok -->
<s:hidden name="t1402" value="%{request.requestSet}"></s:hidden><!-- no -->

<s:hidden name="t1501" value="%{#request.objVVV333.name}"></s:hidden><!--ok -->

<s:hidden name="t1601" value="%{#contextMap[cont]}"></s:hidden><!-- no -->
<s:hidden name="t1602" value="%{#contextMap.cont}"></s:hidden><!-- ok -->

<s:hidden name="t1701" value="%{#objVVV[name]}"></s:hidden><!-- no -->
<s:hidden name="t1702" value="%{#objVVV.name}"></s:hidden><!-- ok -->
<s:hidden name="t1703" value="%{#request.objVVV.name}"></s:hidden><!-- ok -->

http://topic.csdn.net/u/20100122/16/048f1ea4-7b3b-41d8-bd77-a1904614d37d.html#replyachor

你可以用%{#request.adminid}
或者用el:
${sessionScope.adminid}


http://blog.sina.com.cn/s/blog_4b6f8d150100kzly.html

$#%的区别:

(a)$用于i8n和struts配置文件
(b)#取得ActionContext的值
(c)%将原本的文本属性解析为ognl,对于本来就是ognl表达式的属性不起作用。参考<s:property>和<s:include>

你可能感兴趣的:(struts2)