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

            }

    }

     

     

  • 相关阅读:
    java 备忘
    C++ 命名规范 (转)
    代码格式规范
    using namespace 由来
    结构体数组 初始化(转)
    Java Servlet系列之Servlet生命周期
    进程,内存,管理 ps,pstree,top,free,vmstat,iftop,lsof,查看网速
    网络基础知识-
    进程作业管理2-kill,前后台作业,并行执行
    计划任务cron,date,时间同步ntp,chrony
  • 原文地址:https://www.cnblogs.com/attilax/p/15197455.html
Copyright © 2011-2022 走看看