14. Home Click Products Show Product Details

Source: Internet
Author: User

1, in the index.jsp to pass the Product ID, add the contents of the href in a tag, href= "${pagecontext.request.contextpath}/product_findbypid.action?pid=<s :p roperty value= "#p. pid"/> "

<s:iterator value= "NList" var= "P" ><li><a target= "_blank" href= "${pagecontext.request.contextpath}/ Product_findbypid.action?pid=<s:property value= "#p. pid"/> "> "data-original=" http://storage.shopxx.net/ Demo-image/3.0/201301/4a51167a-89d5-4710-aca2-7c76edc355b8-thumbnail.jpg "style=" Display:block; " ></a></li></s:iterator>

2, Productaction.java

Package Cn.xdy.shop.product.action;import Cn.xdy.shop.product.service.productservice;import Cn.xdy.shop.product.vo.product;import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actionsupport;import Com.opensymphony.xwork2.modeldriven;public class ProductAction Extends Actionsupport implements Modeldriven<product>{private Productservice productservice;private Product Product = new product ();p ublic void Setproductservice (Productservice productservice) {This.productservice = Productservice;} Public String Findbypid () {Product = Productservice.findbypid (Product.getpid ()); return "Findbypid";} Public product Getmodel () {return Product;}}

3, the method of adding findbypid in Productservice.java

/** * According to the PID query product information * @param PID * @return */public product findbypid (Integer pid) {return productdao.findbypid (PID);}

4. Join in Productdao.javaMethods of Findbypid

/** * Search items by ID * @param pid * @return */public product findbypid (Integer pid) {return this.gethibernatetemplate (). Get (Prod Uct.class, PID);}

5. Struts.xml Configuration

<!--item---    <action name= "product_*" class= "productaction" method= "{1}" >    <result name= " Findbypid ">/WEB-INF/jsp/product.jsp</result>    </action>

6, ApplicationContext

<!--item action--><bean id= "productaction" class= "Cn.xdy.shop.product.action.ProductAction" scope= " Prototype "><property name=" Productservice "ref=" Productservice "/></bean>

7, product.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%@ taglib uri= "/struts-tags" prefix= "s" %><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

14. Home Click Products Show Product Details

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.