凡是要表示web资源的地址,比如浏览器地址栏中,都是 /
凡是要表示硬盘地址, 都是 \ 

 

public class ServletDemo1 extends HttpServlet {

    //实际开发过程中的地址写法
    //如果地址是给服务器用的, / 代表当前web应用
   //如果地址是给客户端用的, / 代表整个网站(一个网站可以有多个web应用)
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //情况有以下几种
        
        //1.转发(服务器)
        request.getRequestDispatcher("/index.jsp").forward(request, response);
        
        //2. 重定向 (客户端)
        response.sendRedirect("/day06/index.jsp");
        
        //3. 获取地址(服务器)
        this.getServletContext().getRealPath("index.jsp");
        
        //4. 获取请求资源(服务器)
        this.getServletContext().getResource("index.jsp");
        
        //JSP上的两种 (客户端)
        /*<a href="/day06/index.jsp">点击</a>
        
        <form action="/day06/index.jsp"></form>*/
        
    }
}

 

相关文章:

  • 2021-10-15
  • 2021-05-04
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-08-04
  • 2022-01-21
  • 2021-10-27
  • 2022-12-23
  • 2022-02-10
  • 2021-10-23
相关资源
相似解决方案