关于用jspSmartUpload控件上传文件并附带参数

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'add_picture.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" href="../css/common.css" mce_href="css/common.css" type="text/css" /> </head> <body> <div align="center" valign="middle"> <form name="form1" action="add_picture_result.jsp" method="post" ENCTYPE="multipart/form-data"> <input type="hidden" name="uploadFlag" value="firstPagePicture"></input> <div id="man_zone"> <table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" class="table_style"> <tr> <td width="20%" class="left_title_1"> <span class="left-title"> 请选择上传哪种图片: </span></td> <td width="80%"> <select name = "selectValue"> <option value="1">图片1</option> <option value="2">图片2</option> <option value="3">图片3</option> </select> </td> </tr> <tr> <td class="left_title_2">请选择需要上传的图片:</td> <td><input type="file" name="file"></input></td> </tr> </table> </div> <div> <input type="submit" name="提交" value="提交"></input> <input type="reset" name="重置" value="重置"></input> </div> </form> </div> </body> </html>

 

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,com.jspsmart.upload.*,java.text.SimpleDateFormat" errorPage=""%> <jsp:useBean id="futil" class="com.upload.FileUploadUtil" /> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>文件上传处理页面</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"> </head> <body> <% // 新建一个SmartUpload对象 SmartUpload su = new SmartUpload(); // 上传初始化 su.initialize(this.getServletConfig(), request, response); // 设定上传限制 // 1.限制每个上传文件的最大长度。 // su.setMaxFileSize(10000); // 2.限制总上传数据的长度。 // su.setTotalMaxFileSize(20000); // 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。 // su.setAllowedFilesList("jpg,JPG"); // 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, //jsp,htm,html扩展名的文件和没有扩展名的文件。 // su.setDeniedFilesList("exe,bat,jsp,htm,html,,"); // 上传文件 su.upload(); String uploadFlag = su.getRequest().getParameter("uploadFlag"); String selectValue = su.getRequest().getParameter("selectValue"); // 将上传文件全部保存到指定目录 String fileUploadPath = futil.getFileUploadPath(uploadFlag); String realPath = this.getServletContext().getRealPath(""); String uploadPath = realPath + "//images//"; //int count1 = su.save(fileUploadPath); //boolean result = futil.fileUploadResult(uploadFlag); // 逐一提取上传文件信息,同时可保存文件。 int count = 0; for(int i=0;i<su.getFiles().getCount();i++) { com.jspsmart.upload.File file = su.getFiles().getFile(i); if(file.isMissing()) continue; if(!"jpg".equals(file.getFileExt()) && !"JPG".equals(file.getFileExt())) continue; // 将文件另存为 out.println(uploadPath + selectValue + ".jpg"); file.saveAs(uploadPath + selectValue + ".jpg"); out.println("OK"); } %> </body> </html>

你可能感兴趣的:(html,String,Class,Path,import,stylesheet)