fileUp.jsp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <%@page import="java.io.File"%>
  2. <%@page import="java.util.Properties"%>
  3. <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
  4. <%@ page import="org.jeecgframework.core.servlet.Uploader" %>
  5. <%@ page import="java.io.FileInputStream" %>
  6. <%
  7. request.setCharacterEncoding( Uploader.ENCODEING );
  8. response.setCharacterEncoding( Uploader.ENCODEING );
  9. String currentPath = request.getRequestURI().replace( request.getContextPath(), "" );
  10. File currentFile = new File( currentPath );
  11. currentPath = currentFile.getParent() + File.separator;
  12. //加载配置文件
  13. String propertiesPath = request.getSession().getServletContext().getRealPath( currentPath + "config.properties" );
  14. Properties properties = new Properties();
  15. try {
  16. properties.load( new FileInputStream( propertiesPath ) );
  17. } catch ( Exception e ) {
  18. //加载失败的处理
  19. e.printStackTrace();
  20. }
  21. Uploader up = new Uploader(request);
  22. up.setSavePath("upload"); //保存路径
  23. String[] fileType = {".rar" , ".doc" , ".docx" , ".zip" , ".pdf" , ".txt" , ".swf", ".wmv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".mov", ".wmv", ".mp4"}; //允许的文件类型
  24. up.setAllowFiles(fileType);
  25. up.setMaxSize(500 * 1024); //允许的文件最大尺寸,单位KB
  26. up.upload();
  27. response.getWriter().print("{'url':'"+up.getUrl()+"','fileType':'"+up.getType()+"','state':'"+up.getState()+"','original':'"+up.getOriginalName()+"'}");
  28. %>