Java源码示例:com.bstek.ureport.console.UReportServlet
示例1
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String path=req.getContextPath()+UReportServlet.URL+URL;
String uri=req.getRequestURI();
String resPath=uri.substring(path.length()+1);
String p="classpath:"+resPath;
if(p.endsWith(".js")){
resp.setContentType("text/javascript");
}else if(p.endsWith(".css")){
resp.setContentType("text/css");
}else if(p.endsWith(".png")){
resp.setContentType("image/png");
}else if(p.endsWith(".jpg")){
resp.setContentType("image/jpeg");
}else if(p.endsWith(".svg")){
resp.setContentType("image/svg+xml");
}else{
resp.setContentType("application/octet-stream");
}
InputStream input=applicationContext.getResource(p).getInputStream();
OutputStream output=resp.getOutputStream();
try{
IOUtils.copy(input, output);
}finally{
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
示例2
@Bean
public ServletRegistrationBean<Servlet> buildUreportServlet(){
return new ServletRegistrationBean<Servlet>(new UReportServlet(), "/ureport/*");
}
示例3
@Bean
public ServletRegistrationBean<Servlet> buildUreportServlet(){
return new ServletRegistrationBean<Servlet>(new UReportServlet(), "/ureport/*");
}