Structs2标签之<s:action>,<s: a action >和<s:url

在上个网上商城项目中 用到了页面请求,url超链接,这里总结下structs2常用的几个页面请求超链接处理标签<s:action>,<s:a action>和 <s:url>。

1.<s:action>标签:进入页面自动加载处理请求,类似与Ajax局部刷新
用法:
<s:action name="admin_top" namespace="/admin" execut
eResult="true">头部</s:action>

例子:main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理科帮网</title>
</head>
<%@include file="/WEB-INF/pages/common/common_admin.jsp"%>
<div id="box">
<!-- top -->
<s:action name="admin_top" namespace="/admin" executeResult="true">头部</s:action>
<div id="mid">
<!-- left -->
<s:action name="admin_left" namespace="/admin" executeResult="true"></s:action>
<!-- right -->
<iframe name="abc" scrolling="auto" frameborder="0" width="705" height="500"></iframe>
<%--
<s:action name="admin_right" namespace="/admin" executeResult="true"></s:action>
--%>
</div>
<div id="bottom"></div>
</div>
</html>


2.<s:a action>标签:超链接标签,需要手动 点击才触发,把Action配置成项目相应的路径,类似与<s:a href>标签
用法:
<s:a action="cart_list" namespace="/product">
<img src="${context_path}/css/images/index_03.gif" width="28"
height="14" /> 我的购物车</s:a> | <s:a action="order_findByCustomer"
namespace="/product">我的订单</s:a> 

例子:index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GO购网络商城by科帮网</title>
<STYLE type="text/css">
</STYLE>
<SCRIPT type="text/javascript">
if (self != top) {
top.location = self.location;
}
</SCRIPT>
</head>
<body>
<%@include file="/WEB-INF/pages/common/head.jsp"%>
<div id="box">
<div id="left">
<div id="left_s01"><s:a action="customer_login" namespace="/customer"><img
src="${context_path}/css/images/index_23.gif" class="imgx5" /></s:a>
<s:a action="customer_reg" namespace="/customer"><img
src="${context_path}/css/images/index_26.gif" class="imgx5" /></s:a><img
src="${context_path}/css/images/index_27.gif" /></div>
<div id="left_s02"><img
src="${context_path}/css/images/index_25.gif" width="489" height="245"
class="imgz5" /></div>
<!-- 类别 -->
<s:iterator value="categories">
<div id="left_x">
<div id="left122">
<table style="float: left;height: auto;width: 678px; vertical-align: middle; ">
    <tr>  
       <td class="word14" style="width: 22px; padding-left: 10px;">
           <s:property value="name"/>
       </td>
        <td style="padding-bottom: 3px;">
<div id="left122_y">
<!-- 二级 -->
<s:if test="!children.isEmpty">
<s:iterator value="children">
<div style="white-space:nowrap; width: 28%;float: left; margin-top: 5px; margin-bottom: 5px; margin-left: 26px;">
<b style="color: #990000;"><s:property value="name" escape="false"/></b> 
<!-- 三级 -->
<s:if test="!children.isEmpty">
<span>
<s:iterator value="children">
<s:a action="product_getByCategoryId" namespace="/product">
<s:param name="category.id" value="id"></s:param>
<s:property value="name" escape="false"/>
</s:a>
</s:iterator>
</span>
</s:if>
</div>
</s:iterator>
</s:if>
</div>
       </td>
    </tr>
</table>
</div>
</div>
</s:iterator>
</div>
<div id="right">
<!-- 商品排行 -->
<div id="rqpgb">
<table width="195" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="195" height="31"><img
src="${context_path}/css/images/index_28.gif" width="195" height="29" /></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td valign="top">
<s:action name="product_findByClick" namespace="/product" executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<!-- 推荐商品 -->
<div id="xpss">
<table width="195" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="195" height="31"><img
src="${context_path}/css/images/08.gif" width="195" height="29" /></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td valign="top">
<s:action name="product_findByCommend" namespace="/product" executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<!-- 热销商品 -->
<div id="rxsp">
<table width="195" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="195" height="31"><img
src="${context_path}/css/images/index_47.gif" width="195" height="29" /></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td valign="top">
<s:action name="product_findBySellCount" namespace="/product" executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<div id="sckf"></div>
</div>
<div id="foot"></div>
</div>
</body>
</html>

3.<s:url >标签:定义Url,然后可以引用
用法:
<s:url action="category_add" namespace="/admin/product"
var="category_add"></s:url>

<div id="category_title">类别管理</div>
<div id="category_sub">
<a target="abc" href="${category_add}">添加类别</a>
</div>

例子:left.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/pages/common/common_admin.jsp" %>
<!-- 类别 -->
<s:url action="category_add" namespace="/admin/product"
var="category_add"></s:url>
<s:url action="category_list" namespace="/admin/product"
var="category_list"></s:url>
<!-- 商品 -->
<s:url action="product_add" namespace="/admin/product" var="product_add"></s:url>
<s:url action="product_list" namespace="/admin/product"
var="product_list"></s:url>
<!-- 订单 -->
<s:url action="order_list" namespace="/admin/product" var="order_list"></s:url>
<s:url action="order_query" namespace="/admin/product" var="order_query"></s:url>
<div id="left">
<div id="left_top"></div>
<div id="left_mid">
<div id="category_title">类别管理</div>
<div id="category_sub">
<a target="abc" href="${category_add}">添加类别</a>
</div>
<div id="category_sub">
<a target="abc" href="/Shop1/admin/product/category_list.do">查看所有类别${category_list}</a>
</div>
<div id="category_title">商品管理</div>
<div id="category_sub">
<a target="abc" href="${product_add}">添加商品</a>
</div>
<div id="category_sub">
<a target="abc" href="${product_list}">查看所有商品</a>
</div>
<div id="category_title">订单管理</div>
<div id="category_sub">
<a target="abc" href="${order_list}">查看订单</a>
</div>
<div id="category_sub">
<a target="abc" href="${order_query}">订单查询</a>
</div>
</div>
</div>

猜你喜欢

转载自wangdingxin.iteye.com/blog/2309991