适用环境:JavaServer Pages. Any JSP 1.2 +Struts2
用法:
Application Scope Attribute
<s:property value="%{#myContextParam}" />
Session Scope Attribute
<s:property value="%{#session.mySessionAttribute}" />
Session Scope Attribute
<s:property value="%{#session.mySessionAttribute}" />
Request Scope Attribute
<s:property value="%{#request.myRequestAttribute}" />
Request Parameter
<s:property value="%{#parameters.myParameter}" />
(e.g. 超链接传参数)
Context Scope Parameter
<s:property value="%{#myContextParam}" />
等等……
---------------------------------华丽的demo分割线---------------------------------------------
首先导入标签库!
<%@ taglib uri="/struts-tags" prefix="s2" %>
放在request作用域的数据:
request.setAttribute("products", products);
猥琐的HTML代码!。。。。。。。
获取request数据!
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath",basePath);
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>商品列表</title>
<link rel="stylesheet" href="${basePath}product/css/type.css" type="text/css"/>
<link type="text/css" rel="stylesheet" href="${basePath}index/common/common.css"/>
<script language="javascript" type="text/javascript" src="${basePath}index/common/jquery132min.js"></script>
<script language="javascript" type="text/javascript" src="${basePath}index/common/common.js"></script>
<style type="text/css">
<!--
.STYLE1 {color: #0000FF}
.STYLE2 {color: #FFFFFF}
.STYLE3 {
color: #FF0000;
font-weight: bold;
font-size: 18px;
}
.STYLE4 {color: #FF6600}
.STYLE5 {color: #FF6600; font-size: 12px; }
.STYLE9 {
font-size: 14px;
color: #FFFFFF;
}
.STYLE12 {
color: #666666;
font-weight: bold;
}
.STYLE13 {
color: #666666;
font-size: 14px;
font-weight: bold;
}
.STYLE14 {font-size: 12px}
body{
margin:0px 0px 0px 0px;
padding:0px;
text-align:center;
}
#Layer0 {
position:relative;
margin:0px auto 0px auto;
height:228px;
z-index:1;
width:929px;
text-align:left;
top:0px;
}
#Layer02 {
position:relative;
width:929px;
height:59px;
z-index:3;
}
#Layer1 {
position:relative;
width:929px;
height:300px;
padding-top:10px;
z-index:5;
}
#bottom {
position:absolute;
width:888px;
height:80px;
z-index:15;
left:73px;
top:1350px;
border:1px solid #D3D2D2;
}
-->
</style>
</head>
<body>
<jsp:include page="../index/top.jsp" flush="false"/>
<div id="Layer0">
<div id="Layer1">
<table width="900" height="100" border="1" cesllpadding="1" cellspacing="0" >
<tr>
<td height="25" colspan="3" class="big1">
<span class="STYLE12">
筛选条件:
</span>
</td>
</tr>
<tr>
<td width="100%" height="100">
<table width="917" border="0">
<tr>
<td width="12"></td>
<td width="98" height="30" align="center"><span class="STYLE13">品牌:</span></td>
<td width="783" class="big1">
<a href="#">品牌名称</a>
</td>
</tr>
<tr>
<td colspan="3"><hr style="border:1px dashed #CCCCCC; height:1px"/> </td>
</tr>
<tr>
<td></td>
<td height="30" align="center"><span class="STYLE13">价格:</span></td>
<td class="big1">
<a href="#">500元及以下</a>
<a href="#">500-1000元</a>
<a href="#">1000-2000元</a>
<a href="#">2000-3000元</a>
<a href="#">3000-4000元</a>
<a href="#">4000元以上</a>
<a href="#">全部</a>
</td>
</tr>
<tr>
<td colspan="3"><hr style="border:1px dashed #CCCCCC; height:1px"/> </td>
</tr>
</table> </td>
</tr>
</table>
<br />
<span class="STYLE14">当前第<font color="#FF0000">1</font>/2页
<a href="#">上一页</a>
<a href="#">下一页</a></span>
<table width="931" height="113" border="1" cellpadding="2" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF" bgcolor="#FFFFEE">
<tr>
<td width="15" height="84" bgcolor="#CCCCCC"></td>
<td width="835">
<table width="900" height="149" border="0">
<tr>
<td width="108"> </td>
<td width="108" height="22"></td>
<td height="27" bgcolor="#FFFFFF" colspan="4">
</td>
</tr>
<s2:iterator var="product" value="%{#request.products}" id="product">
<tr>
<td width="148" class="big2"><img src="${basePath}product/images/<s2:property value="%{#product.pimage}" />"
width="80" height="80" border="0" title="点击浏览"/></td>
<td width="200" height="116" class="big2">
名称:<s2:property value="%{#product.pname}"/><br />
屏幕尺寸:<s2:iterator var="parameter" value="%{#product.parameters}">
<s2:property value="%{#parameter.screensize}" />
</s2:iterator>
<br />
系列:<s2:property value="%{#product.series}" /></td>
<td width="300" height="116" class="big2">
系统:
<s2:iterator var="parameter" value="%{#product.parameters}">
<s2:property value="%{#parameter.os}" />
</s2:iterator>
<br />
CPU:
<s2:iterator var="parameter" value="%{#product.parameters}">
<s2:property value="%{#parameter.cpu}" />
</s2:iterator>
</td>
<td width="159" height="116" class="big2">
内存容量: <s2:iterator var="parameter" value="%{#product.parameters}">
<s2:property value="%{#parameter.memcap}" />
</s2:iterator><br />
硬盘容量: <s2:iterator var="parameter" value="%{#product.parameters}">
<s2:property value="%{#parameter.diskcap}" />
</s2:iterator>
</td>
<td width="109" rowspan="2" class="big2">
颜色/价格:
<br />
<s2:iterator var="color" value="%{#product.colorses}">
<s2:property value="%{#color.color}" />/<s2:property value="%{#color.price}" /><br />
</s2:iterator>
</td>
<td width="84" rowspan="2" class="big2">
<a href="#">加入购物车</a>
</td>
</tr>
</s2:iterator>
</table>
</td>
</tr>
</table>
</div>
</div>
<!-- bottom -->
<div id="bottom">
<jsp:include page="../index/bottom.jsp" flush="true"/>
</div>
</body>
</html>
来源:小伙伴开发网http://www.kaifaer.com
分享到:
相关推荐
struts2 中 OGNL表达式的使用struts2 中 OGNL表达式的使用
struts2中ognl表达式的用法,详细介绍了ognl表达式与struts2基本标签的结合。
struts2OGNL表达式ActionContext及valuesStack.pdf
ognl表达式 ognl表达式 ognl表达式 ognl表达式
NULL 博文链接:https://chaoyi.iteye.com/blog/2158731
OGNL是对象图导航语言(即该表达式访问的是对象及对象的属性)
Struts 2默认的表达式语言是OGNL,原因是它相对其它表达式语言具有下面几大优势: 1、 支持对象方法调用,如xxx.doSomeSpecial(); 2、支持类静态的方法调用和值访问,表达式的格式为@[类全名(包括包路径)]@...
主要介绍了Struts2 OGNL表达式实例详解,相关实例代码,需要的朋友可以参考。
struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号
Struts2的标签库及OGNL表达式语言
NULL 博文链接:https://cdxs2.iteye.com/blog/1926840
struts2标签和OGNL表达式struts2标签和OGNL表达式
struts2-OGNL表达式测试代码
NULL 博文链接:https://johnson2132.iteye.com/blog/720769
本资源适合刚接触Struts和Ognl的小伙伴交流学习,欢迎吐槽。
NULL 博文链接:https://takeme.iteye.com/blog/1668255
最近的项目开发中使用了struts2的框架,但是好多人都不清楚struts2的标签的具体的用法,要想完全掌握struts2标签的用法,那么你必须先精通了struts2中OGNL的用法。struts2中很多东西其实理解就行,但是惟独OGNL虽然...
struts2标签和OGNL表达式.pdf
ognl表达式在struts中的用法解析
JS:ognl表达式 JS:ognl表达式 JS:ognl表达式