SSH网上商城—图片显示功能

  SSH网上商城已经完成了,现在对一些常用的知识进行总结,方便以后再学习!

          图片显示功能:

          1、点击首页时出现下面图片


          2、代码

          点击首页:

<li><a href="${ pageContext.request.contextPath }/index.action">首页</a> |</li>

         去struts配置文件中找index的模块

<!-- 配置首页访问的Action -->
		<action name="index" class="indexAction">
			<result name="index">/WEB-INF/jsp/index.jsp</result>
		</action>

         去spring配置文件中找indexAction 模块

<!-- 首页访问的Action -->
	<bean id="indexAction" class="cn.itcast.shop.index.action.IndexAction" scope="prototype">
		<property name="categoryService" ref="categoryService"/>
		<property name="productService" ref="productService"/>
	</bean>
         F3点击 spring 中class中的路径,去Action中查找方法。 在点击首页链接的时候,index模块后面没有跟要在Action中查找的方法,所以便会去找Action的默认方法。

          

/**
	 * 执行的访问首页的方法, 默认执行此方法
	 */
	public String execute(){
		//查询所有一级分类的集合
		List<Category> cList = categoryService.findAll();
		//将一级分类存入到session的范围;
		ActionContext.getContext().getSession().put("cList", cList);
		
		//查询热门商品
		List<Product> hList=productService.findHot();
		//保存到值栈中
		ActionContext.getContext().getValueStack().set("hList", hList);
		
		//查询最新商品
		List<Product> nList = productService.findNew();
		//保存到值栈中
		ActionContext.getContext().getValueStack().set("nList", nList);
		return "index";
	}
         Action中的findAll()方法会经过—service—Dao最后在放回到Action中的cList 集合中,然后将返回的结果放到session中。

         前台页面从session中取值。

         (1)引入struts2的标签库

<%@ taglib uri="/struts-tags" prefix="s" %>  
          (2)遍历session 取值

  <s:iterator var="p" value="hList">
       <li>
	   <a href="${ pageContext.request.contextPath }/product_findByPid.action?pid=<s:property value="#p.pid"/>" target="_blank"><img src="${pageContext.request.contextPath}/<s:property value="#p.image"/>" data-original="http://storage.shopxx.net/demo-image/3.0/201301/0ff130db-0a1b-4b8d-a918-ed9016317009-thumbnail.jpg" style="display: block;">
           </a>
       </li>
 </s:iterator>	
          

           其中struts2 的标签库是功能、session的使用还是非常期待后面学习的时候,深入的总结!

           总结:学习的过程中遇到新的知识,一定要做个标记,知道是在哪里用的了。当时自己可能没有时间,或是不理解所以没有总结,但是如果自己做了标记,等以后回来在学习的时候可以很快的找到。然后再次学习!  这次总结的以后图片存储利用的map 结构,but 用的list 、想找找哪里用到了map 吧!哎,没有做标记,记住这次教训!!!




          

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值