Atitit spirngboot 访问 html文件总结 自设计web服务器原理与实现
Url路由压力,读取url,获得项目更路径绝对路径,拼接为文件路径。读取文建内容输出即可
目录路径 upload。Html在项目跟目录
默认的要佳配置文件和放入指定目录。。麻烦放弃此种方法
使用springboot 拦截器测试,老是拦截不到uri ,都是/error
使用java的filter拦截,效果良好。。
http://localhost:8080/upload.html
@Component @WebFilter(urlPatterns = "/*", filterName = "authFilter") public class AuthFilter implements Filter {
@Override public void destroy() { // TODO Auto-generated method stub
}
@Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { HttpServletRequest httpServletRequest=(HttpServletRequest) arg0; HttpServletResponse httpServletResponse= (HttpServletResponse) arg1; String uri= httpServletRequest.getRequestURI(); System.out.println(uri); String url= httpServletRequest.getRequestURL().toString(); if(uri.endsWith(".html")) { String classFilePath = this.getClass().getResource("/").getPath(); String prjpath=new File(classFilePath).getParent(); String htmlpath=prjpath+uri; byte[] s=FileUtils.readFileToByteArray(new File(htmlpath)); ServletOutputStream outputStream = httpServletResponse.getOutputStream(); outputStream.write(s); outputStream.flush(); } }
|