网上商城前端页面框架的搭建及源码
最近做了个网上商城的项目,闲下来总结下前端前台后台框架的搭建
前台:
1.web.xml配置欢迎页面
<!--设置程序的默认欢迎页面-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
2.欢迎页面index.jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
<!--这里刷新加载请求-->
<METAHTTP-EQUIV="Refresh"CONTENT="0;URL=index.do">
</head>
<body>
<center>
<imgsrc="<%=request.getContextPath()%>/css/images/load.gif"><br>
<p>页面加载中......</p>
</center>
</body>
</html>
3.前台structs-front.xml的配置(包括index请求配置)
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--前台登录-->
<packagename="shop.front"extends="shop-default">
<!--配置拦截器-->
<interceptors>
<!--验证用户登录的拦截器--><!--怎么拦截的?凭啥拦截?怎么看他拦截的是啥?还有啥时候财拦截???-->
<interceptorname="loginInterceptor"class="com.lyq.action.interceptor.CustomerLoginInteceptor"/>
<interceptor-stackname="customerDefaultStack">
<interceptor-refname="loginInterceptor"/>
<interceptor-refname="defaultStack"/>
</interceptor-stack>
</interceptors>
<actionname="index"class="indexAction">
<result>/WEB-INF/pages/index.jsp</result>
</action>
</package>
<!--消费者Action-->
<packagename="shop.customer"extends="shop-default"namespace="/customer">
<actionname="customer_*"method="{1}"class="customerAction">
<resultname="input">/WEB-INF/pages/user/customer_reg.jsp</result>
</action>
</package>
<!--商品Action-->
<packagename="shop.product"extends="shop-default"namespace="/product">
<actionname="product_*"class="productAction"method="{1}">
<resultname="list">/WEB-INF/pages/product/product_list.jsp</result>
<resultname="select">/WEB-INF/pages/product/product_select.jsp</result>
<resultname="clickList">/WEB-INF/pages/product/product_click_list.jsp</result>
<resultname="findList">/WEB-INF/pages/product/product_find_list.jsp</result>
</action>
</package>
<!--购物车Action-->
<packagename="shop.cart"extends="shop.front"namespace="/product">
<actionname="cart_*"class="cartAction"method="{1}">
<resultname="list">/WEB-INF/pages/cart/cart_list.jsp</result>
<interceptor-refname="customerDefaultStack"/>
</action>
</package>
<!--订单Action-->
<packagename="shop.order"extends="shop.front"namespace="/product">
<actionname="order_*"class="orderAction"method="{1}">
<resultname="add">/WEB-INF/pages/order/order_add.jsp</result>
<resultname="confirm">/WEB-INF/pages/order/order_confirm.jsp</result>
<resultname="list">/WEB-INF/pages/order/order_list.jsp</result>
<resultname="error">/WEB-INF/pages/order/order_error.jsp</result>
<interceptor-refname="customerDefaultStack"/>
</action>
</package>
</struts>
4.加载index.do请求,查询出主商品类别等基础信息进入前台index.jsp主页面
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
<title>GO购网络商城by科帮网</title>
<STYLEtype="text/css">
</STYLE>
<SCRIPTtype="text/javascript">
if(self!=top){
top.location=self.location;
}
</SCRIPT>
</head>
<body>
<%@includefile="/WEB-INF/pages/common/head.jsp"%>
<divid="box">
<divid="left">
<divid="left_s01"><s:aaction="customer_login"namespace="/customer"><img
src="${context_path}/css/images/index_23.gif"class="imgx5"/></s:a>
<s:aaction="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>
<divid="left_s02"><img
src="${context_path}/css/images/index_25.gif"width="489"height="245"
class="imgz5"/></div>
<!--类别-->
<s:iteratorvalue="categories">
<divid="left_x">
<divid="left122">
<tablestyle="float:left;height:auto;width:678px;vertical-align:middle;">
<tr>
<tdclass="word14"style="width:22px;padding-left:10px;">
<s:propertyvalue="name"/>
</td>
<tdstyle="padding-bottom:3px;">
<divid="left122_y">
<!--二级-->
<s:iftest="!children.isEmpty">
<s:iteratorvalue="children">
<divstyle="white-space:nowrap;width:28%;float:left;margin-top:5px;margin-bottom:5px;margin-left:26px;">
<bstyle="color:#990000;"><s:propertyvalue="name"escape="false"/></b>
<!--三级-->
<s:iftest="!children.isEmpty">
<span>
<s:iteratorvalue="children">
<s:aaction="product_getByCategoryId"namespace="/product">
<s:paramname="category.id"value="id"></s:param>
<s:propertyvalue="name"escape="false"/>
</s:a>
</s:iterator>
</span>
</s:if>
</div>
</s:iterator>
</s:if>
</div>
</td>
</tr>
</table>
</div>
</div>
</s:iterator>
</div>
<divid="right">
<!--商品排行-->
<divid="rqpgb">
<tablewidth="195"border="0"cellpadding="0"
cellspacing="0">
<tr>
<tdwidth="195"height="31"><img
src="${context_path}/css/images/index_28.gif"width="195"height="29"/></td>
</tr>
<tr>
<tdheight="5"></td>
</tr>
<tr>
<tdvalign="top">
<s:actionname="product_findByClick"namespace="/product"executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<!--推荐商品-->
<divid="xpss">
<tablewidth="195"border="0"cellpadding="0"
cellspacing="0">
<tr>
<tdwidth="195"height="31"><img
src="${context_path}/css/images/08.gif"width="195"height="29"/></td>
</tr>
<tr>
<tdheight="5"></td>
</tr>
<tr>
<tdvalign="top">
<s:actionname="product_findByCommend"namespace="/product"executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<!--热销商品-->
<divid="rxsp">
<tablewidth="195"border="0"cellpadding="0"
cellspacing="0">
<tr>
<tdwidth="195"height="31"><img
src="${context_path}/css/images/index_47.gif"width="195"height="29"/></td>
</tr>
<tr>
<tdheight="5"></td>
</tr>
<tr>
<tdvalign="top">
<s:actionname="product_findBySellCount"namespace="/product"executeResult="true"></s:action>
</td>
</tr>
</table>
</div>
<divid="sckf"></div>
</div>
<divid="foot"></div>
</div>
</body>
</html>
5.index.jsp主页面开始加载页头,加载主商品基本信息链接,<s:action>开始加载热销,推荐商品
后台管理:
1.配置后台管理的structs-admin.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--后台管理-->
<packagename="shop.admin"namespace="/admin"extends="shop-default">
<!--配置拦截器-->
<interceptors>
<!--验证用户登录的拦截器-->
<interceptorname="loginInterceptor"class="com.lyq.action.interceptor.UserLoginInterceptor"/>
<interceptor-stackname="adminDefaultStack">
<interceptor-refname="loginInterceptor"/>
<interceptor-refname="defaultStack"/>
</interceptor-stack>
</interceptors>
<actionname="admin_*"class="indexAction"method="{1}">
<resultname="top">/WEB-INF/pages/admin/top.jsp</result>
<resultname="left">/WEB-INF/pages/admin/left.jsp</result>
<resultname="right">/WEB-INF/pages/admin/right.jsp</result>
<interceptor-refname="adminDefaultStack"/>
</action>
</package>
<packagename="shop.admin.user"namespace="/admin/user"extends="shop-default">
<actionname="user_*"method="{1}"class="userAction"></action>
</package>
<!--类别管理-->
<packagename="shop.admin.category"namespace="/admin/product"extends="shop.admin">
<actionname="category_*"method="{1}"class="productCategoryAction">
<resultname="list">/WEB-INF/pages/admin/product/category_list.jsp</result>
<resultname="input">/WEB-INF/pages/admin/product/category_add.jsp</result>
<resultname="edit">/WEB-INF/pages/admin/product/category_edit.jsp</result>
<interceptor-refname="adminDefaultStack"/>
</action>
</package>
<!--商品管理-->
<packagename="shop.admin.product"namespace="/admin/product"extends="shop.admin">
<actionname="product_*"method="{1}"class="productAction">
<resultname="list">/WEB-INF/pages/admin/product/product_list.jsp</result>
<resultname="input">/WEB-INF/pages/admin/product/product_add.jsp</result>
<resultname="edit">/WEB-INF/pages/admin/product/product_edit.jsp</result>
<interceptor-refname="adminDefaultStack"/>
</action>
</package>
<!--订单管理-->
<packagename="shop.admin.order"namespace="/admin/product"extends="shop.admin">
<actionname="order_*"method="{1}"class="orderAction">
<resultname="list">/WEB-INF/pages/admin/order/order_list.jsp</result>
<resultname="select">/WEB-INF/pages/admin/order/order_select.jsp</result>
<resultname="query">/WEB-INF/pages/admin/order/order_query.jsp</result>
<resultname="update">/WEB-INF/pages/admin/order/order_update_success.jsp</result>
<interceptor-refname="adminDefaultStack"/>
</action>
</package>
</struts>
2.user_logon.action请求执行进入后台页面,登录成功则跳转到全局返回变量main.jsp后台管理主页面中去,失败继续在后台登录页面
http://localhost:8080/Shop1/admin/user/user_logon.do
3.进入后台管理主页面main.jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
<title>后台管理科帮网</title>
</head>
<%@includefile="/WEB-INF/pages/common/common_admin.jsp"%>
<divid="box">
<!--top-->
<s:actionname="admin_top"namespace="/admin"executeResult="true">头部</s:action>
<divid="mid">
<!--left-->
<s:actionname="admin_left"namespace="/admin"executeResult="true"></s:action>
<!--right-->
<iframename="abc"scrolling="auto"frameborder="0"width="705"height="500"></iframe>
<%--
<s:actionname="admin_right"namespace="/admin"executeResult="true"></s:action>
--%>
</div>
<divid="bottom"></div>
</div>
</html>
4.加载后台管理页面main.jsp,加载里面的<s:action>加载头部top.jsp,左边left.jsp
5.头部top.jsp,左边left.jsp
top.jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%@includefile="/WEB-INF/pages/common/common_admin.jsp"%>
<divid="top">
<divid="toptiao">
<imgsrc="${context_path}/css/images/flower.gif"width="12"height="12"/>
您好科帮网,<s:propertyvalue="#session.admin.username"/>!
<s:aaction="user_logout"namespace="/admin/user">
<imgsrc="${context_path}/css/images/ht_02_02.gif"width="55"height="20"align="middle"/>
</s:a>
</div>
</div>
left.jsp:<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%@includefile="/WEB-INF/pages/common/common_admin.jsp"%>
<!--类别-->
<s:urlaction="category_add"namespace="/admin/product"
var="category_add"></s:url>
<s:urlaction="category_list"namespace="/admin/product"
var="category_list"></s:url>
<!--商品-->
<s:urlaction="product_add"namespace="/admin/product"var="product_add"></s:url>
<s:urlaction="product_list"namespace="/admin/product"
var="product_list"></s:url>
<!--订单-->
<s:urlaction="order_list"namespace="/admin/product"var="order_list"></s:url>
<s:urlaction="order_query"namespace="/admin/product"var="order_query"></s:url>
<divid="left">
<divid="left_top"></div>
<divid="left_mid">
<divid="category_title">类别管理</div>
<divid="category_sub">
<atarget="abc"href="${category_add}">添加类别</a>
</div>
<divid="category_sub">
<atarget="abc"href="/Shop1/admin/product/category_list.do">查看所有类别${category_list}</a>
</div>
<divid="category_title">商品管理</div>
<divid="category_sub">
<atarget="abc"href="${product_add}">添加商品</a>
</div>
<divid="category_sub">
<atarget="abc"href="${product_list}">查看所有商品</a>
</div>
<divid="category_title">订单管理</div>
<divid="category_sub">
<atarget="abc"href="${order_list}">查看订单</a>
</div>
<divid="category_sub">
<atarget="abc"href="${order_query}">订单查询</a>
</div>
</div>
</div>
6.点击left.jsp里面的超链接相应的操作,加载都右边right里面来