美文网首页
2018-02-28 path路径小结

2018-02-28 path路径小结

作者: 紫杉叶子 | 来源:发表于2018-03-01 00:24 被阅读0次
// 1.  转发 的时候
        request.getRequestDispatcher("/servlet2").forward(request, response);
        
        //2. 重定向的时候
        response.sendRedirect("/day11/1.html");
        
        //3. 读取 web应用下资源文件的时候  --- 在web 应用根目录下有一个 1.txt 文件
        getServletContext().getRealPath("/1.txt");
        
        // 4.  表单 提交数据的时候 
        // <form action="/day11/servlet2">
        
        // 5. 超链接 a 标签 的时候 
        //  <a href="/day12/1.jsp"></a>
        
        // 6. 写了 img 标签, src 
        // <img src="/day11/checkimage">
        
        
        //7. url重写       http://.../servlet;jsessionid=KSDFLKDSJFLKJDS
        response.encodeURL("/day11/servlet2");
        
//      =========================================================
        
        // 8. 使用类加载器 获得文件的 路径的时候 
        PathSummayServlet.class.getClassLoader().getResource("4.txt");
        
        
        InputStream in = PathSummayServlet.class.getClassLoader().getResourceAsStream("6.jpg");
        
        InputStream in2 = getServletContext().getResourceAsStream("/WEB-INF/classes/6.jpg");
        
        // PathSummayServlet.class.getResource("/4.txt");

相关文章

网友评论

      本文标题:2018-02-28 path路径小结

      本文链接:https://www.haomeiwen.com/subject/dflwxftx.html