smartUpload简单使用

来源:互联网 发布:c语言strncmp函数实现 编辑:程序博客网 时间:2024/05/21 20:27




一:将jar包导入tomcat

复制到*\apache-tomcat-6.0.30\lib


二:jsp

<html><body><form action="smartUploadDemo.jsp" method="post" enctype="multipart/form-data">封转后不能传递参数:<input type="text" name="NoParam"><br>选择上传文件:<input type="file" name="upfile"><br><input type="submit" value="上传">            </form>  </body></html>


<%@ page contentType="text/html" pageEncoding="GBK"%><%@ page import="org.lxh.smart.*"%> //包名称打开下载的jar包,根绝看文件结构要修改<html><body><%SmartUpload smart = new SmartUpload();smart.initialize(pageContext);smart.upload();//封装后只能用这种方法得到表单中的ParameterString name = smart.getRequest().getParameter("NoParam");//得到数组0,中的拓展名String ext = smart.getFiles().getFile(0).getFileExt();smart.save("SUpload");//执行存储,存储到哪个文件夹%>限制文件类型的正则<%=smart.getFiles().getFile(0).getFileName().matches("^\\w+.(jpg|gif)$")%></body></html>



三:新建upload文件夹

在虚拟目录根目录下,创建名为“SUpload”的文件夹,接收上传数据



四:文件上传重命名



五:限制上传类型

限制文件类型的正则<%=smart.getFiles().getFile(0).getFileName().matches("^\\w+.(jpg|gif)$")%>



六:多文件上传


原创粉丝点击