码迷,mamicode.com
首页 > 编程语言 > 详细

【j2ee spring】40、巴巴运动网的产品添加修改选择

时间:2015-07-10 15:29:03      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:j2ee   巴巴运动网   hibernate4   struts2-0   spring   

巴巴运动网的产品添加修改选择

1、项目图解

技术分享

技术分享

2、我们开始做我们的相应的功能模块
页面的素材我会上传的,链接是:http://download.csdn.net/detail/cutter_point/8803985

产品的添加界面add_product.jsp

<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>添加产品</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../css/vip.css" type="text/css">
<SCRIPT type="text/javascript" src="../js/FoshanRen.js"></SCRIPT>
<%-- <script type="text/javascript" src="../js/jscripts/tiny_mce/tiny_mce.js"></script> --%>
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="gbk" src="../ueditor/lang/zh-cn/zh-cn.js"></script>

<style type="text/css">
   div{
       width:100%;
   }
</style>


<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor(‘editor‘)就能拿到相关的实例
    var ue = UE.getEditor(‘editor‘);


    function isFocus(e){
        alert(UE.getEditor(‘editor‘).isFocus());
        UE.dom.domUtils.preventDefault(e);
    }
    function setblur(e){
        UE.getEditor(‘editor‘).blur();
        UE.dom.domUtils.preventDefault(e);
    }
    function insertHtml() {
        var value = prompt(‘插入html代码‘, ‘‘);
        UE.getEditor(‘editor‘).execCommand(‘insertHtml‘, value);
    }
    function createEditor() {
        enableBtn();
        UE.getEditor(‘editor‘);
    }
    function getAllHtml() {
        alert(UE.getEditor(‘editor‘).getAllHtml());
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为:");
        arr.push(UE.getEditor(‘editor‘).getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为:");
        arr.push(UE.getEditor(‘editor‘).getPlainTxt());
        alert(arr.join(‘\n‘));
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent(‘欢迎使用ueditor‘)方法可以设置编辑器的内容");
        UE.getEditor(‘editor‘).setContent(‘欢迎使用ueditor‘, isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor(‘editor‘).setDisabled(‘fullscreen‘);
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor(‘editor‘).setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
        var range = UE.getEditor(‘editor‘).selection.getRange();
        range.select();
        var txt = UE.getEditor(‘editor‘).selection.getText();
        alert(txt);
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为:");
        arr.push(UE.getEditor(‘editor‘).getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为:");
        arr.push(UE.getEditor(‘editor‘).hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor(‘editor‘).focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor(‘editor‘).destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById(‘btns‘);
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById(‘btns‘);
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor(‘editor‘).execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor(‘editor‘).execCommand( "clearlocaldata" );
        alert("已清空草稿箱");
    }

    function Formfield(name, label)
    {
        this.name=name;
        this.label=label;
    }

    function verifyForm(objForm)
    {
        //手动把 文本域的值赋给textarea表单元素
        var des = document.getElementById("editor");
        if(UE.getEditor(‘editor‘).hasContents() == true)    //如果文本域里面有内容的话
        {
            des.value = UE.getEditor(‘editor‘).getPlainTxt();
        }
        //alert(des.value);

        var list  = new Array(new Formfield("name", "产品名称"),new Formfield("typeid", "产品类型"),
        new Formfield("baseprice", "产品底价"),new Formfield("marketprice", "产品市场价")
        ,new Formfield("sellprice", "产品销售价"),new Formfield("description", "产品描述"),
        new Formfield("stylename", "产品图片的样式"),new Formfield("imagefile", "产品图片"));
        for(var i=0;i<list.length;i++)
        {
            var objfield = eval("objForm."+ list[i].name);
            if(trim(objfield.value)=="")
            {
                alert(list[i].label+ "不能为空");
                if(objfield.type!="hidden" && objfield.focus()) objfield.focus();
                return false;
            }
        }
        var imagefile = objForm.imagefile.value;
        var ext = imagefile.substring(imagefile.length-3).toLowerCase();
        if (ext!="jpg" && ext!="gif" && ext!="bmp" && ext!="png")
        {
            alert("只允许上传gif、jpg、bmp、png!");
            return false; 
        }
        return true;
    }


    function SureSubmit()
    {
        var objForm = document.getElementById("form1");
        if (verifyForm(objForm)) 
            objForm.submit();
    } 

</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<s:form id="form1" action="productmanage-add" enctype="multipart/form-data" method="post">
<s:hidden name="typeid"/>
  <table width="98%" border="0" cellspacing="1" cellpadding="3" align="center">
    <tr bgcolor="6f8ac4"> 
      <td colspan="2" ><font color="#FFFFFF">添加产品:</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">产品名称  :</div></td>
      <td width="75%"> <input type="text" name="name" size="50" maxlength="40" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">产品类别<font color="#FF0000">*</font></div></td>
      <td width="75%"> <input type="text" name="v_type_name" disabled="true" size="30"/> 
        <input type="button" name="select" value="选择..." onClick="javaScript:winOpen(‘<s:url action="select-productmanage"/>‘,‘列表‘,600,400)">(<a href="<s:url action=‘/control/product/type/manage‘/>?method=addUI">添加产品类别</a>)
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">底(采购)价 :</div></td>
      <td width="75%"> <input type="text" name="baseprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">市场价 :</div></td>
      <td width="75%"> <input type="text" name="marketprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">销售价 :</div></td>
      <td width="75%"> <input type="text" name="sellprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">货号 :</div></td>
      <td width="75%"> <input type="text" name="code" size="20" maxlength="30" onclick="javascript:InputLongNumberCheck()" />(注:供货商提供的便于产品查找的编号)</td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">产品图片 (不同颜色/样式):</div></td>
      <td width="75%"> 样式名称:<input name="stylename" type="text" size="10">样式图片<input type="file" name="imagefile" size="30"></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> 
        <div align="right">品牌 :</div>
      </td>
      <td width="75%"> 
        <select name="brandid">
            <option value="">***无***</option>
            <s:iterator value="#request.brands" var="brand">
                <option value="<s:property value="#brand.code" />"><s:property value="#brand.name" /> </option>
            </s:iterator>
        </select>
        (<a href="##">添加品牌</a>)
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> 
            <div align="right">适用性别 :</div>
      </td>
      <td width="75%">
        <select name="sex">
            <option value="NONE">男女不限</option>
            <option value="MAN">男士</option>
            <option value="WOMEN">女士</option>
        </select>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">型号 :</div></td>
      <td width="75%"> <input type="text" name="model" size="35" maxlength="30" /></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">重量 :</div></td>
      <td width="75%"> <input type="text" name="weight" size="10" maxlength="10" onclick="" /></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">购买说明 :</div></td>
      <td width="75%"> <input type="text" name="buyexplain" size="35" maxlength="30" /></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%" valign="top"> <div align="right">产品简介<font color="#FF0000">*</font></div></td>
      <td width="75%"> 
        <textarea id="editor" name="description" style="width:1024px;height:500px;" ></textarea>
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td colspan="2"> <div align="center"> 
          <input type="button" name="Add" value=" 确 认 " class="frm_btn" onClick="javascript:SureSubmit()" />
          &nbsp;&nbsp;<input type="button" name="Button" value=" 返 回 " class="frm_btn" onclick="" />
        </div></td>
    </tr>
  </table>
</s:form>
<br>
</body>
</html>

我们的页面控制器action

/**
 * 功能:这个是产品的管理动作
 * 时间:2015年5月27日17:17:45
 * 文件:ProductManageAction.java
 * 作者:cutter_point
 */
package com.cutter_point.web.action.product;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cutter_point.bean.QueryResult;
import com.cutter_point.bean.product.Brand;
import com.cutter_point.bean.product.ProductInfo;
import com.cutter_point.bean.product.ProductStyle;
import com.cutter_point.bean.product.ProductType;
import com.cutter_point.bean.product.Sex;
import com.cutter_point.service.product.BrandService;
import com.cutter_point.service.product.ProductInfoService;
import com.cutter_point.service.product.ProductTypeService;
import com.cutter_point.utils.SiteUrl;
import com.cutter_point.web.formbean.product.ProductForm;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
public class ProductManageAction extends ActionSupport implements ServletRequestAware, ModelDriven<ProductForm>
{
    private static final long serialVersionUID = 6647552432813142686L;
    @Resource
    private ProductInfoService pis; //注入产品服务类
    @Resource
    private BrandService bs;    //注入品牌服务类
    @Resource
    private ProductTypeService pts; //注入产品类型服务类
    private HttpServletRequest request;
    private ProductForm pf;

    /**
     * 显示产品修改界面
     * @return String struts2的返回跳转result
     * @throws Exception
     */
    public String editUI() throws Exception
    {
        //从数据库中获取相应的产品信息,根据id号获取相应的信息
        ProductInfo product = pis.find(ProductInfo.class, pf.getProductid());
        //获取产品名称
        pf.setName(product.getName());
        //设置类别id
        pf.setTypeid(product.getType().getTypeid());
        //底(采购)价
        pf.setBaseprice(product.getBaseprice());
        //市场价
        pf.setMarketprice(product.getMarketprice());
        //销售价 
        pf.setSellprice(product.getSellprice());
        //货号 
        pf.setCode(product.getCode());
        //品牌 
        if(product.getBrand() != null)
        {
            //如果对应的品牌不为空
            pf.setBrandid(product.getBrand().getCode());
        }
        //适用性别 
        pf.setSex(product.getSexrequest().toString());
        //型号 
        pf.setModel(product.getModel());
        //重量 :
        pf.setWeight(product.getWeight());
        //购买说明
        pf.setBuyexplain(product.getBuyexplain());
        //产品简介
        pf.setDescription(product.getDescription());
        //性别合适的人群
        request.setAttribute("sexname", product.getSexrequest().getName());
        //吧当前选择的品牌传出去
        request.setAttribute("brand", product.getBrand());
        //类别名称显示出来
        request.setAttribute("typename", product.getType().getName());  //吧类型显示出来
        request.setAttribute("brands", bs.getScrollData(Brand.class).getResultList());  //吧品牌显示出来
        return "edit";
    }

    /**
     * 产品修改
     * @return String struts2的返回跳转result
     * @throws Exception
     */
    public String edit() throws Exception
    {
        ProductInfo product = pis.find(ProductInfo.class, pf.getProductid());   //查询出这个产品
        product.setName(pf.getName());  //获取产品名称
        product.setBaseprice(pf.getBaseprice());        //设置基础价格
        product.setSellprice(pf.getSellprice());        //设置销售价格
        product.setMarketprice(pf.getMarketprice());    //市场价
        if(pf.getBrandid() != null && !"".equals(pf.getBrandid().trim()))
        {
            product.setBrand(new Brand(pf.getBrandid()));       //设置品牌的id
        }
        product.setBuyexplain(pf.getBuyexplain());  //购买说明
        product.setCode(pf.getCode());      //货号
        product.setDescription(pf.getDescription());        //产品描述
        product.setModel(pf.getModel()); //设置型号
        product.setWeight(pf.getWeight()); //重量
        product.setSexrequest(Sex.valueOf(pf.getSex())); //性别要求
        product.setType(new ProductType(pf.getTypeid()));   //设置产品类型

        /***************************************************************************************************************
         *                  产品信息保存到数据库                                                                          ****
         ***************************************************************************************************************/
        pis.update(product);    //保存这个产品,当保存完了之后hibernate会吧这个产品的id号赋值给product


        /***************************************************************************************************************
         *                              跳转成功之后页面传值                                                                **
         ***************************************************************************************************************/
        request.setAttribute("message", "产品修改成功");
        request.setAttribute("urladdress", SiteUrl.readUrl("control.product.list"));
        return "message";
    }

    /**
     * 显示类别选择界面
     * @return String struts2的返回跳转result
     * @throws Exception
     */
    public String selectUI() throws Exception
    {
        String sql = "o.parentid is null";  //如果是顶级目录的话
        Object[] parems = new Object[0];    //设定相应的id号
        if(pf.getTypeid() != null && pf.getTypeid() > 0)
        {
            sql = " o.parentid = ? ";
            parems = new Object[]{pf.getTypeid()};
        }
        QueryResult<ProductType> qr = pts.getScrollData(ProductType.class, -1, -1, sql, parems);
        request.setAttribute("types", qr.getResultList());
        return "typeselect";
    }

    /**
     * 显示产品添加界面
     * @return String struts2的返回跳转result
     * @throws Exception
     */
    public String addUI() throws Exception
    {
        request.setAttribute("brands", bs.getScrollData(Brand.class).getResultList());
        return "add";
    }

    /**
     * 产品添加
     * @return String struts2的返回跳转result
     * @throws Exception
     */
    public String add() throws Exception
    {
        ProductInfo product = new ProductInfo();    //新建一个产品
        product.setName(pf.getName());  //获取产品名称
        product.setBaseprice(pf.getBaseprice());        //设置基础价格
        product.setSellprice(pf.getSellprice());        //设置销售价格
        product.setMarketprice(pf.getMarketprice());    //市场价
        if(pf.getBrandid() != null && !"".equals(pf.getBrandid().trim()))
        {
            product.setBrand(new Brand(pf.getBrandid()));       //设置品牌的id
        }
        product.setBuyexplain(pf.getBuyexplain());  //购买说明
        product.setCode(pf.getCode());      //货号
        product.setDescription(pf.getDescription());        //产品描述
        product.setModel(pf.getModel()); //设置型号
        product.setWeight(pf.getWeight()); //重量
        product.setSexrequest(Sex.valueOf(pf.getSex())); //性别要求
        product.setType(new ProductType(pf.getTypeid()));   //设置产品类型

        //用来保存图片路径
        //再上传之前判断上传图片类型是不是符合要求
        if(!pf.validateFileType("logofile"))
        {
            request.setAttribute("message", "图片格式不对");
            request.setAttribute("urladdress", SiteUrl.readUrl("control.brand.list"));
            return "message";
        }
        //得到图片后缀
        String ext = pf.getImagefileFileName().substring(pf.getImagefileFileName().lastIndexOf(‘.‘));
        if(pf.getImagefile().length() > 409600)
        {
            request.setAttribute("message", "图片不能大于400k");
            request.setAttribute("urladdress", SiteUrl.readUrl("control.brand.list"));
            return "message";
        }

        /***************************************************************************************************************
         *                  产品信息保存到数据库                                                                          ****
         ***************************************************************************************************************/
        //G:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\babaSport_1100_brand\images\ 这个就是realpath
        String realpath = ServletActionContext.getServletContext().getRealPath("/images");
        product.addProductStyle(new ProductStyle(pf.getStylename(), pf.getImagefileFileName()));    //这个里面放文件存放的名字和路径
        pis.save(product);  //保存这个产品,当保存完了之后hibernate会吧这个产品的id号赋值给product

        /***************************************************************************************************************
         *                              文件上传                                                                          **
         ***************************************************************************************************************/
        String showpath = "";
        String logopathdir = realpath + "product\\" + pf.getTypeid() +"\\" +product.getId()+ "\\phototype";
        File logosavedir = new File(logopathdir);   //文件的保存路径
        //文件的显示地址
        showpath = "..\\" + logosavedir.toString().substring(logosavedir.toString().lastIndexOf("\\images"));
        //判断文件是否获取,文件获取到,且长度大于0
        if(pf.getImagefile() != null && pf.getImagefile().length() > 0)
        {
            if(!logosavedir.exists())
            {
                //如果文件保存路径不存在,我们就创建这个路径
                logosavedir.mkdirs();
            }
            String imagename = UUID.randomUUID().toString() + ext;  //构建文件名称
            //这里用文件流来传进来
            FileOutputStream fos = null;
            FileInputStream fis = null;
            try
            {
                String logopath = logosavedir + "\\" + imagename;
                showpath += "\\" + imagename;
                //建立文件输出流
                fos = new FileOutputStream(logopath);
                //建立文件上传流
                fis = new FileInputStream(pf.getImagefile());
                //设定一个字节缓存
                byte[] buffer = new byte[2048];
                int len = 0;        //每次上传的长度
                //不断地从文件上传流输出到输出流
                while((len = fis.read(buffer)) != -1)
                {
                    //输出
                    fos.write(buffer, 0, len);
                }
            } 
            catch (Exception e)
            {
                System.out.println("文件上传失败");
                e.printStackTrace();
            }
            finally
            {
                this.close(fos, fis);
            }
        }

        /***************************************************************************************************************
         *                              跳转成功之后页面传值                                                                **
         ***************************************************************************************************************/
        request.setAttribute("message", "产品添加成功");
        request.setAttribute("urladdress", SiteUrl.readUrl("control.product.list"));
        return "message";
    }

    //管理文件流
    protected void close(FileOutputStream fos, FileInputStream fis)
    {
        if(fis != null)
        {
            try
            {
                fis.close();
            } 
            catch (Exception e)
            {
                System.out.println("关闭文件输入流失败");
                e.printStackTrace();
            }
        }

        if(fos != null)
        {
            try
            {
                fos.close();
            } 
            catch (Exception e)
            {
                System.out.println("关闭文件输出流失败");
                e.printStackTrace();
            }
        }
    }

    @Override
    public void setServletRequest(HttpServletRequest arg0)
    {
        this.request = arg0;
    }

    public ProductInfoService getPis()
    {
        return pis;
    }

    public void setPis(ProductInfoService pis)
    {
        this.pis = pis;
    }

    public BrandService getBs()
    {
        return bs;
    }

    public void setBs(BrandService bs)
    {
        this.bs = bs;
    }

    public ProductForm getPf()
    {
        return pf;
    }

    public void setPf(ProductForm pf)
    {
        this.pf = pf;
    }

    @Override
    public ProductForm getModel() 
    {
        if(pf == null)
            pf = new ProductForm();

        return pf;
    }
}

修改界面edit_product.jsp

<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>修改产品</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/vip.css" type="text/css">
<SCRIPT type="text/javascript" src="../js/FoshanRen.js"></SCRIPT>
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="gbk" src="../ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="gbk" src="../ueditor/lang/zh-cn/zh-cn.js"></script>

<style type="text/css">
   div{
       width:100%;
   }
  </style>

<script type="text/javascript" type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor(‘editor‘)就能拿到相关的实例
    var ue = UE.getEditor(‘editor‘);

    //页面对select进行赋值
    var sex = document.getElementById("sex");
    if(sex.nodeName != null)
    {
        sex
    }

    function isFocus(e){
        alert(UE.getEditor(‘editor‘).isFocus());
        UE.dom.domUtils.preventDefault(e);
    }
    function setblur(e){
        UE.getEditor(‘editor‘).blur();
        UE.dom.domUtils.preventDefault(e);
    }
    function insertHtml() {
        var value = prompt(‘插入html代码‘, ‘‘);
        UE.getEditor(‘editor‘).execCommand(‘insertHtml‘, value);
    }
    function createEditor() {
        enableBtn();
        UE.getEditor(‘editor‘);
    }
    function getAllHtml() {
        alert(UE.getEditor(‘editor‘).getAllHtml());
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为:");
        arr.push(UE.getEditor(‘editor‘).getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为:");
        arr.push(UE.getEditor(‘editor‘).getPlainTxt());
        alert(arr.join(‘\n‘));
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent(‘欢迎使用ueditor‘)方法可以设置编辑器的内容");
        UE.getEditor(‘editor‘).setContent(‘欢迎使用ueditor‘, isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor(‘editor‘).setDisabled(‘fullscreen‘);
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor(‘editor‘).setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
        var range = UE.getEditor(‘editor‘).selection.getRange();
        range.select();
        var txt = UE.getEditor(‘editor‘).selection.getText();
        alert(txt);
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为:");
        arr.push(UE.getEditor(‘editor‘).getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为:");
        arr.push(UE.getEditor(‘editor‘).hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor(‘editor‘).focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor(‘editor‘).destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById(‘btns‘);
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById(‘btns‘);
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor(‘editor‘).execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor(‘editor‘).execCommand( "clearlocaldata" );
        alert("已清空草稿箱");
    }

function Formfield(name, label){
    this.name=name;
    this.label=label;
}
function verifyForm(objForm)
{
    var list  = new Array(new Formfield("name", "产品名称"),new Formfield("typeid", "产品类型"),
    new Formfield("baseprice", "产品底价"),new Formfield("marketprice", "产品市场价")
    ,new Formfield("sellprice", "产品销售价"),new Formfield("description", "产品描述"));
    for(var i=0;i<list.length;i++){
        var objfield = eval("objForm."+ list[i].name);
        if(trim(objfield.value)==""){
            alert(list[i].label+ "不能为空");
            if(objfield.focus()) objfield.focus();
            return false;
        }
    }
    return true;
}
function SureSubmit(){
    var form1 = document.getElementById("form");
    if(verifyForm(form1)) 
    {
        form1.submit();
    }
} 
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<s:form name="form1" id="form" action="productmanage-edit" enctype="multipart/form-data" method="post">
<s:hidden name="typeid"/>
<s:hidden name="productid"/>
  <table width="98%" border="0" cellspacing="1" cellpadding="3" align="center">
    <tr bgcolor="6f8ac4"> 
      <td colspan="2" ><font color="#FFFFFF">修改产品:</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">产品名称  :</div></td>
      <td width="75%"> <input type="pf.name" value="<s:property value="name"/>" name="name" size="50" maxlength="40" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">产品类别<font color="#FF0000">*</font></div></td>
      <td width="75%"> <input type="text" name="v_type_name" value="<s:property value="#request.typename"/>" disabled="true" size="30"/>  
        <input type="button" name="select" value="选择..." onClick="javaScript:winOpen(‘<s:url action="select-productmanage"/>‘,‘列表‘,600,400)">(<a href="<html:rewrite action=‘/control/product/type/manage‘/>?method=addUI">添加产品类别</a>)
      </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">底(采购)价 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="baseprice"/>" name="baseprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" />元 <font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">市场价 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="marketprice"/>" name="marketprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" />元 <font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">销售价 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="sellprice"/>" name="sellprice" size="10" maxlength="10" onclick="javascript:InputLongNumberCheck()" />元 <font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">货号 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="code"/>" name="code" size="20" maxlength="30" />(注:供货商提供的便于产品查找的编号)</td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">品牌 :</div></td>
      <td width="75%">
      <select name="brandid">
            <option value="<s:property value="#request.brand.code" />"> <s:property value="#request.brand.name" /> </option>
            <s:iterator value="#request.brands" var="brand">
                <option value="<s:property value="#brand.code" />"><s:property value="#brand.name" /> </option>
            </s:iterator>
        </select>
        (<a href="##">添加品牌</a>)</td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">适用性别 :</div></td>
      <td width="75%"> 
        <select name="sex" > 
            <option value="<s:property value="sex"/>"> <s:property value="#request.sexname" /> </option>
            <option value="NONE">男女不限</option>
            <option value="MAN">男士</option>
            <option value="WOMEN">女士</option>
        </select>
        </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">型号 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="model"/>" name="model" size="35" maxlength="30" /></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">重量 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="weight"/>" name="weight" size="10" maxlength="10" onclick="" />克</td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">购买说明 :</div></td>
      <td width="75%"> <input type="text" value="<s:property value="buyexplain"/>" name="buyexplain" size="35" maxlength="30" /></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%" valign="top"> <div align="right">产品简介<font color="#FF0000">*</font></div></td>
      <td width="75%"><textarea id="editor" name="description" style="width:1024px;height:500px;" > <s:property value="description"/> </textarea></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td colspan="2"> <div align="center"> 
          <input type="button" name="edit" value=" 确 认 " class="frm_btn" onClick="javascript:SureSubmit()">
          &nbsp;&nbsp;<input type="button" name="Button" value=" 返 回 " class="frm_btn" onclick="javascript:history.back()">
        </div></td>
    </tr>
  </table>
</s:form>
<br>
</body>
</html>

产品类型选择productTypeSelect.jsp

<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title> 类别选择 </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/vip.css" type="text/css">
<SCRIPT type="text/javascript" src="../js/FoshanRen.js"></SCRIPT>
<SCRIPT type="text/javascript" src="../js/xmlhttp.js"></SCRIPT>

<SCRIPT type="text/javascript">
function checkIt()
{
    var objForm = document.forms[0];
    var form = opener.document.forms[0];
    if (form)
    {
        form.typeid.value = objForm.dicId.value;
        form.v_type_name.value = objForm.dicName.value;
    }
    window.close();
}
function getDicName(dicId,strDicName)
{
    var objForm = document.forms[0];
    objForm.dicId.value = dicId;
    objForm.dicName.value = strDicName;
}
function getTypeList(typeid){
        var typecontent = document.getElementById(‘typecontent‘);
        if(typecontent){
            typecontent.innerHTML= "数据正在加载...";
            send_request(function(value){typecontent.innerHTML=value;}, ‘<html:rewrite action="/control/product/type/manage"/>?method=gettypelist&typeid=‘+ typeid, true);
        }
}
</SCRIPT>
<style>
<!--
.inputText{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #666666;
    border: 1px solid #999999;
}
body {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 12px;
    color: #666666;
}
-->
</style>
</head>

<body>
产品类别列表,请选择分类:<br>
导航:<a href=‘<s:url action="##"/>‘>顶级目录</a>
<form method="post" name="main" action="">
<input type="hidden" name="dicId" >
<input type="hidden" name="dicName">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
    <tr>
        <td id="typecontent">
            <table width="100%" border="0">
                <tr>
                    <s:iterator value="#request.types" var="type" status="loop">
                        <td id="typecontent">
                            <s:if test="#type.childtypes.size > 0">
                                <s:a action="select-productmanage?typeid=%{#type.typeid}"><s:property value="#type.name"/>  </s:a>
                            </s:if>
                            <s:if test="#type.childtypes.size == 0">
                                <input type="radio" name="typeid" onclick="getDicName(‘<s:property value="#type.typeid"/>‘,‘<s:property value="#type.name"/>‘)" value="<s:property value="#type.typeid"/>"> <s:property value="#type.name"/>  
                            </s:if>
                        </td>
                        <s:if test="#loop.count % 5 == 0">
                            </tr><tr>
                        </s:if>
                    </s:iterator>
                </tr>
            </table>
        </td>
    </tr>
    <tr><td colspan="2" align="center">
        <input type=‘button‘ name=‘create‘ value=" 确 认 " onClick="javascript:checkIt()">
        <input type=‘button‘ name="cancel" onClick="javaScript:window.close()" value=" 取 消 "> 
    </td></tr>
</table>
</form>
</body>
</html>

3、struts2的配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <include file="struts-default.xml" />
    <constant name="struts.ObjectFactory" value="spring" /> <!--    表示这里面的action由spring进行创建 -->
    <constant name="struts.devMode" value="true" />
    <!--解决乱码    -->
    <constant name="struts.i18n.encoding" value="UTF-8" />

    <package name="control" namespace="/control" extends="struts-default">
        <global-results>
            <result name="message">/page/share/message.jsp</result>
        </global-results>
        <action name="center-*"><!-- 直接跳转,不需要经过class的验证,默认返回success -->
            <result name="success">/page/controlcenter/{1}.jsp</result>
        </action>
        <!-- 产品类别展示 -->
        <action name="producttypelist" class="productTypeAction" method="execute">
            <result name="list">/page/product/producttypelist.jsp</result>
        </action>
        <!-- 产品类别管理 -->
        <action name="*-producttypemanage" class="productTypeManageAction" method="{1}UI">
            <result name="{1}">/page/product/{1}_productType.jsp</result>
        </action>
        <action name="producttypemanage-*" class="productTypeManageAction" method="{1}">
            <result name="{1}">/page/product/{1}_productType.jsp</result>
        </action>
        <!-- 品牌类别展示 -->
        <action name="brandlist" class="brandAction" method="execute">
            <result name="list">/page/product/brandlist.jsp</result>
        </action>
        <!-- 品牌类别管理 -->
        <action name="*-brandmanage" class="brandManageAction" method="{1}UI">
            <result name="{1}">/page/product/{1}_brand.jsp</result>
        </action>
        <action name="brandmanage-*" class="brandManageAction" method="{1}">
            <result name="{1}">/page/product/{1}_brand.jsp</result>
        </action>
        <!-- 文件展示 -->
        <action name="uploadfilelist" class="uploadFileAction" method="execute">
            <result name="list">/page/uploadfile/uploadfilelist.jsp</result>
        </action>
        <!-- 文件上传管理 -->
        <action name="*-filemanage" class="uploadfileManageAction" method="{1}">
            <result name="{1}">/page/uploadfile/{1}.jsp</result>
            <result name="fileuploadfinish">/page/uploadfile/fileuploadfinish.jsp</result>
            <result name="error">/page/uploadfile/error.jsp</result>
        </action>
        <!-- 产品分页展示 -->
        <action name="productlist" class="productAction" method="execute">
            <result name="list">/page/product/productlist.jsp</result>
        </action>
        <!-- 产品管理 -->
        <action name="*-productmanage" class="productManageAction" method="{1}UI">
            <result name="{1}">/page/product/{1}_product.jsp</result>
            <result name="type{1}">/page/product/productTypeSelect.jsp</result>
        </action>
        <action name="productmanage-*" class="productManageAction" method="{1}">
            <result name="{1}">/page/product/{1}_product.jsp</result>
        </action>
    </package>
</struts>

4、接下来我们测试一下页面的效果

我们访问这个网站

http://localhost:8080/ babaSport_1400_productinfo/control/center-main

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享

6、总结

产品的修改与增加,这里使用了一个富文本编辑框,看起来就酷炫

版权声明:本文为博主原创文章,未经博主允许不得转载。

【j2ee spring】40、巴巴运动网的产品添加修改选择

标签:j2ee   巴巴运动网   hibernate4   struts2-0   spring   

原文地址:http://blog.csdn.net/cutter_point/article/details/46828867

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!