日期:2014-05-16  浏览次数:20390 次

jsp图片不在工程内的显示
1.src=‘请求路径’
2.后台代码


public void doGetImage(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
	        response.setContentType("text/html; charset=GBK");
	        response.setContentType("image/jpeg");
	        
	        FileInputStream inputs = new FileInputStream(filePath+"1371190361756.jpg");
	        OutputStream output = response.getOutputStream();
	        
	        try {
	            int count = 0;
	            byte[] buffer = new byte[1024*8];
	            while ( (count = inputs.read(buffer)) != -1 )
	            	output.write(buffer, 0, count);
	        } finally {
	        	if(inputs!=null){  
	                try {  
	                    inputs.close();  
	                } catch (IOException e) {  
	                    e.printStackTrace();  
	                }  
	             }  
	             if(output!=null){  
	                try {  
	                    output.close();  
	                } catch (IOException e) {  
	                    e.printStackTrace();  
	                }  
	             }
	        }
	    }