当前位置: 代码迷 >> 综合 >> web工程中各类路径的写法
  详细解决方案

web工程中各类路径的写法

热度:26   发布时间:2023-10-25 13:43:41.0
通常都是以“/”开头
如果是给服务器用的那么/代表web应用;如果是给浏览器用的那么就代表网站(一个网站下面有多个web应用)。
“/,\”两种斜杠如果想获取url地址打一个正斜杠/,如果是硬盘里的资源就是反斜杠\。

以下是实例代码



package roberthu;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletDemo3 extends HttpServlet {


 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //1.服务器用的
  request.getRequestDispatcher("/new.html").forward(request, response);
  
  //2.浏览器用的
  response.sendRedirect("/day023/new.html");
  
  //3.服务器用的
  this.getServletContext().getRealPath("/new.html");
  
  //4.服务器用的
  this.getServletContext().getResourceAsStream("/new.html");
  
  //5.
  /*给网站用的
   * <a href="/day023/new.html"></a>
   *
   * 给网站用的
   * <form action="/day023/new.html">
   *
   * </form>
   * */
 }


 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doGet(request,response);
 }

}


  相关解决方案