上代碼吧
/**
* 關(guān)于路徑問題 的 總結(jié)
* @param response
* @throws IOException
*/
private void test4(HttpServletResponse response) throws IOException {
//1.只要是寫地址 都統(tǒng)統(tǒng)用 / 開頭
//2.要是"/"是給服務(wù)器用的則代表 這個 web資源
this.getServletContext().getRealPath("/...");//這個 "/" 是相對于服務(wù)器來說的
this.getServletContext().getRequestDispatcher("/...");//轉(zhuǎn)發(fā) 也是相對服務(wù)器說的
//要是 "/"是給瀏覽器用的則代表webapps
response.sendRedirect("/...");//重定向 相對于瀏覽器來說的
//3.當程序處理url資源的時候 用"/",程序讀取硬盤資源 用"\\"
FileOutputStream fileOutputStream=new FileOutputStream("F:\\java");//讀取硬盤上的數(shù)據(jù)
}