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();

            }

    }

     

     

  • 相关阅读:
    Nginx 缓存解决方案
    Chrome去水印、自由复制的解决方法
    简单介绍正向代理和反向代理
    Lambda表达式
    项目集成hystrix-dashboard
    hystrix 添加turbine
    GsonUtil 工具类
    idea 去除import * 变成具体引入文件
    eureka 创建服务消费者
    eureka 创建注册服务提供方
  • 原文地址:https://www.cnblogs.com/attilax/p/15197455.html
Copyright © 2011-2022 走看看