当前位置: 代码迷 >> JavaScript >> jsp图片不在工程内的展示
  详细解决方案

jsp图片不在工程内的展示

热度:319   发布时间:2013-07-01 12:33:04.0
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();  
	                }  
	             }
	        }
	    }
  相关解决方案