smartupload image upload

A jsp webpage demo (product addition)

①First, there is a form submission on the addgoods page

 <form action="doaddgoods.jsp" method="post" enctype="multipart/form-data">(设为二进制)
      <li>商品名称:<input type="text" name="gname"> </li>
  <li>商品价格:<input type="text" name="gprice"> </li>
  <li>商品描述:<input type="text" name="ginfo"> </li>
      <p>
        <label> 商品图片 </label>
        <input name="file" type="file" class="opt_input" />
      </p>
      <input type="submit" value="提交" class="opt_sub" />
      <input type="reset" value="重置" class="opt_sub" />
    </form>

②Add goods on the doaddgoods page (pay attention to importing the smartuploadjar package)

//Instantiate a smartUpload object 
SmartUpload su=new SmartUpload(); su.initialize(pageContext); //Set the file types allowed to upload  su.setAllowedFilesList("jpg,png,gif,txt,doc"); //Set File types that are prohibited from uploading  su.setDeniedFilesList("exe,bat,js,jsp,css"); //Limit the size of uploaded files  su.setMaxFileSize(1024*1024*3); //Set the encoding format  su.setCharset(" utf-8"); //Start uploading memory  su.upload(); String path="images\\"; File file=su.getFiles().getFile(0); if(!file.isMissing()){ file.setCharset("utf-8"); path+=file.getFileName(); file.saveAs(path,SmartUpload.SAVE_VIRTUAL); } //Receive the value in turn Request req=su.getRequest(); (to import under smartupload request method)





























String gname=req.getParameter("gname");
String gprice=req.getParameter("gprice");
String ginfo=req.getParameter("ginfo");
IGoodsBiz ib=new GoodsBiz();
Goods g=new Goods(gname,Integer.parseInt(gprice),ginfo,path);
int n=ib.addgoods(g);
if(n>0){
out.print("<script>alert('添加商品成功');location.href='/p4/admin.jsp';</script>");
}
else{
out.print("<script>alert('添加商品失败');location.href='/p4/addgoods.jsp';</script>");
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326685407&siteId=291194637