java的jap页面上文件上传,所需jar包:jspSmartUpload.jar

红色为关键代码
index.jap
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
......

    
enctype="multipart/form-data"> 上传:
PhotoUpload.jsp
<%@ page language="java" import="java.util.*,com.jspsmart.upload.SmartUpload" pageEncoding="gbk"%>
    <%
    	SmartUpload su = new SmartUpload();
    	//加载表单数据到SmartUpload  内置对象中pageContext
    	su.initialize(pageContext);
    	try{
	    	//限制格式
	    	su.setAllowedFilesList("png");
	    	//限制大小,字节
	    	su.setMaxFileSize(200000000);
	    	//上传
	    	su.upload();
	    	//指定保存位置
	    	su.save("C:/Users/Administrator/Desktop/img");
	    	out.println("添加成功");
	    }catch(Exception e){
	    	if(e.getMessage().startsWith("Size")){
	    		out.println("");
	    	}else{
	    		out.println("");

	    	}
	    
	    }
     %>
  


你可能感兴趣的:(java)