Atitit spirngboot 訪問 html檔案總結 自設計web伺服器原理與實現 Url路由壓力,讀取url,獲得專案更路徑絕對路徑,拼接為檔案路徑。讀取文建內容輸出即可 目錄路徑 u
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 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(); } }
|