`
zds420
  • 浏览: 198438 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

Struts2 之struts tags

 
阅读更多

Struts2 的struts 标签

 

 

实战

 

strutstags.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'ognl.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
 
     
    
    Struts2标签使用:<br/>
    1:<!--<s:a href="/ognl.action" target="_blank">aaaaaaaaaaaa</s:a><br/>
    2:action使用:<s:action name="ognl"   executeResult="true"></s:action>--><br/>
    3:set 使用:<s:set name="var_set" value="100"></s:set> &nbsp; &nbsp; 查看结果<s:property value="#var_set"/>
  </body>
</html>

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'strutstags.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body> 
  		数据标签,展示标签:<br/>
		1:set 使用:<s:set var="person_name" value="'100'"></s:set> &nbsp; &nbsp; 查看结果:<s:property value="#person_name"/><br/>
		2:text 使用:<s:text name="i18n.label.greetings" >
			<s:property/>
		</s:text>	<br/>
		3:url 使用:<s:url ></s:url><br/>
		4:bean 使用:<s:bean name="com.summary.model.TitesModel" var="author1">
						<s:property value="#author1.author"/>
						<s:property value="#author1.getReply_to()"/>
					</s:bean><br/>
					
		5:s:include 使用:<s:include value="/index.jsp"></s:include><br/>
		6:s:fielderror 使用:  <s:fielderror name="error_message"></s:fielderror><br/>
		<hr/>
		控制标签<br/>
		<br/>
		7:if elseif else使用:<br/>
		<s:if test="#parameters.age[0] >= 22">你可以结婚了</s:if><br/>
		<s:elseif test="#parameters.age[0] < 22 && #parameters.age[0]>1">你不可以结婚</s:elseif><br/>
		<s:else>输入错误</s:else><br/>
		8:iterator使用:
		<br/>
		<s:iterator value="{1,2,3,4,5,6,7,8,9,10}">
			值:<s:property/>|
		</s:iterator>
			<br/>
		循环自定义变量:	<br/>
		<s:iterator value="{'aaa','bbb','ccc','ddd','eee','fff','gggg'}" var="my_var">
			值:<s:property value="#my_var.toUpperCase()"/>|
		</s:iterator>
		<br/>
		dataInfoList数据的显示:
		<s:iterator value="dataInfoList" var="user_list">
			备注:<s:property value="#user_list.remark"/> &nbsp; 	 
			学校:<s:property value="#user_list.school"/> &nbsp;	<br/>	 <!-- 此处使用;自定义变量名.属性名称 -->
		</s:iterator>
		<br/>
		<s:iterator value="dataInfoList" var="user_list" status="status">
			<s:property value="#user_list.school"/>
			统计当前数据记录总数:<s:property value="#status.count"/><br/>
		</s:iterator>
		
		循环键值:#{中间放入变量数组和集合} 定义Map为什么需要加"#"号<br/>
		<!-- 
		<s:iterator value="#{1:'a'}" >
			值:<s:property value="key"/>|<br/>
		</s:iterator>
		 -->
		<br/>
  		<s:debug></s:debug>
  </body>
</html>

 

struts.xml

<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
	<package name="default" namespace="/" extends="struts-default">
		<action name="ognl" class="com.struts2.action.OGNLController">
			<result>/ognl.jsp</result>
		</action>
		<action name="strutstags" class="com.struts2.action.OGNLController">
			<result>/strutstags.jsp</result>
		</action>
		
</package>
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics