zoukankan      html  css  js  c++  java
  • 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= (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();

            }

    }

     

     

  • 相关阅读:
    VMware Workstation Pro下载密钥
    hypervisor
    Xmanager6 下载地址
    linux常用命令
    linux常用
    查看机器端口信息
    windows下快捷键
    SpringMVC学习笔记整理
    2017面试题收集
    oracle 常用知识点整理
  • 原文地址:https://www.cnblogs.com/attilax/p/15197455.html
Copyright © 2011-2022 走看看