国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

易買網(wǎng)之smartupload實現(xiàn)文件上傳

2019-11-15 00:37:26
字體:
來源:轉載
供稿:網(wǎng)友
易買網(wǎng)之smartupload實現(xiàn)文件上傳

經(jīng)過倆個星期的奮斗,易買網(wǎng)項目完工。在之前,實現(xiàn)圖片的上傳,走過許多彎路,原來是好多基礎的知識忘記了,沒把smartupload文件包添加組件jar包至WEB-INF/lib包中,在此特別重視,做下文件的上傳。

第一步:創(chuàng)建商品實體類:

package entity;public class easybuy_PRoductn {    private int  ep_id ;//編號    private String  ep_name  ;//名字    private String  ep_description ;//描述    private int  ep_price;//價格    private int  ep_stock  ;//庫存    private int  epc_id ;//父類id    private int  epc_child_id ;//二級id    private String  ep_file_name  ;//文件名    private int  tiaoma ;//條碼號    public int getEp_id() {        return ep_id;    }    public void setEp_id(int epId) {        ep_id = epId;    }    public String getEp_name() {        return ep_name;    }    public void setEp_name(String epName) {        ep_name = epName;    }    public String getEp_description() {        return ep_description;    }    public void setEp_description(String epDescription) {        ep_description = epDescription;    }    public int getEp_price() {        return ep_price;    }    public void setEp_price(int epPrice) {        ep_price = epPrice;    }    public int getEp_stock() {        return ep_stock;    }    public void setEp_stock(int epStock) {        ep_stock = epStock;    }    public int getEpc_id() {        return epc_id;    }    public void setEpc_id(int epcId) {        epc_id = epcId;    }    public int getEpc_child_id() {        return epc_child_id;    }    public void setEpc_child_id(int epcChildId) {        epc_child_id = epcChildId;    }    public String getEp_file_name() {        return ep_file_name;    }    public void setEp_file_name(String epFileName) {        ep_file_name = epFileName;    }    public int getTiaoma() {        return tiaoma;    }    public void setTiaoma(int tiaoma) {        this.tiaoma = tiaoma;    }}

第二步:編寫sql:

//添加商品public int Produt(String epName, String epDescription, int epPrice,        int epStock, int epcId, String epFileName,String ep_name_tiaoma) {        //創(chuàng)建數(shù)據(jù)庫的鏈接     con=this.getConnection();        //創(chuàng)建int值確認是否插入成功    int i=0;        //創(chuàng)建sql語句    String sql="insert into  easybuy_productn values(easybuy_productn_seq.nextval,?,?,?,?,?,'',?,?)";        try {        //寫入sql        st=con.prepareStatement(sql);        st.setString(1, epName);        st.setString(2, epDescription);        st.setInt(3, epPrice);        st.setInt(4, epStock);        st.setInt(5, epcId);        st.setString(6, epFileName);        st.setString(7, ep_name_tiaoma);                //開始執(zhí)行sql        i=st.executeUpdate();                //開始判斷        if(i>0){            i=1;        }else{            i=0;        }        //釋放鏈接        this.ShiFang(rs, st, con);            } catch (SQLException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }                return i;}

添加商品jsp頁面

<h2>添加商品</h2>        <div class="manage">            <form action="manage/MyJsp.jsp" method="post" enctype="multipart/form-data">                <table class="form">                    <tr>                        <td class="field">描述描述:</td>                        <td><input type="text" class="text" name="productName" id="productscript" value="鐵三角 Audio-Technica ATH-EQ300M-SV 銀色 掛耳式耳機" /></td>                    </tr>                                        <tr>                        <td class="field">所屬分類:</td>                        <td>                        <select name="parentId">                             <c:forEach var="news" items="${requestScope.flist1}" >                         <option value="1">${news.epc_name}</option>                                                     <c:forEach var="ck" items="${flist}" >                 <c:if test="${ck.epc_parent_id == news.epc_id}">                                <option value="3">${ck.epc_name}</option>                                </c:if>                              </c:forEach>                                </c:forEach>                                                            </select>                        </td>                    <tr>                        <td class="field">頭像:</td>                        <td><input type="file" name="fileg" id="imgOne" onchange="preImg(this.id,'imgPre');"/></td>                    </tr>                    <tr>                <td>頭像預覽:</td>                <td><img id="imgPre" src="" style="width:150px;height:150px;display:block;"/></td>                  </tr>                    <tr>                        <td class="field">商品價格:</td>                        <td><input type="text" class="text tiny" name="productPrice" id="productPrice" /> 元</td>                    </tr>                    <tr>                        <td class="field">名稱:</td>                        <td><input type="text" class="text" name="productName2" id="productName" /></td>                    </tr>                    <tr>                        <td class="field">庫存:</td>                        <td><input type="text" class="text tiny" name="productName3" id="producstock"/></td>                    </tr>                        <tr>                        <td class="field">條號碼:</td>                        <td><input type="text" class="text tiny" name="productName4" id="producstock"/></td>                    </tr>                                                        <tr>                        <td></td>                        <td><label class="ui-blue"><input type="submit" name="submit" value="添加" /></label></td>                    </tr>                </table>            </form>

處理頁面:

<%//----處理上傳文件/*    使用smartupload        1、添加組件jar包至WEB-INF/lib包中        2、設置form表單的提交類型為二進制類型*///創(chuàng)建smartupload組件SmartUpload su = new SmartUpload();//初始化組件上下文su.initialize(pageContext);//設置編碼su.setCharset("utf-8");try{    //上傳文件    su.upload();}catch(Exception e){    %>        <script type="text/javascript">            alert("不允許上傳:bat,exe,jsp,html,htm,java,class文件類型");            location.href="index.jsp";        </script>    <%}//獲取單個文件File file = su.getFiles().getFile(0);//設置上傳服務器的位置String path2 = "upload//";//得到上傳文件的名稱String filename = file.getFileName();//上傳文件的路徑path2 = path2 + filename;//保存文件file.saveAs(path2,SmartUpload.SAVE_VIRTUAL);//獲取圖片顯示路徑String path3="upload//"+filename;//獲取用戶的名稱String productName = su.getRequest().getParameter("productName");//獲取用戶的分類int parentId = Integer.parseInt(su.getRequest().getParameter("parentId"));//獲取用戶價格int productPrice=Integer.parseInt(su.getRequest().getParameter("productPrice"));//獲取用戶的品牌String productName2=su.getRequest().getParameter("productName2");//獲取用戶的庫存int productPrice3=Integer.parseInt(su.getRequest().getParameter("productName3"));//獲取用戶的條碼號String productPrice5=su.getRequest().getParameter("productName4");//實例化添加對象productnBiz product=new productnBizImpl();//調用查詢方法int i=product.Produt(productName2,productName,productPrice,productPrice3,parentId,path3,productPrice5);//判斷添加新聞是否成功if(i>0){            out.print("<script>");        out.print("alert('添加成功');");        out.print("location.href='product.jsp';");        out.print("</script>");}else{    request.getRequestDispatcher("product-add.jsp").forward(request,response);}%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>     <title>My JSP 'Product_Add.jsp' starting page</title>        <meta http-equiv="pragma" content="no-cache">    <meta http-equiv="cache-control" content="no-cache">    <meta http-equiv="expires" content="0">        <meta http-equiv="keyWords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="This is my page">    <!--    <link rel="stylesheet" type="text/CSS" href="styles.css">    -->  </head>    <body>    This is my JSP page. <br>  </body></html>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 南乐县| 普定县| 申扎县| 五常市| 上虞市| 石屏县| 年辖:市辖区| 商都县| 腾冲县| 神农架林区| 任丘市| 临沧市| 崇左市| 西昌市| 本溪市| 兴化市| 蒙阴县| 江口县| 海南省| 大方县| 汾西县| 鹤壁市| 秀山| 江都市| 河池市| 泽库县| 额尔古纳市| 资源县| 道真| 象州县| 藁城市| 正阳县| 五原县| 天全县| 前郭尔| 长武县| 闽侯县| 文山县| 皮山县| 闸北区| 清新县|