web工程中分客戶端瀏覽器要訪問的地址和服務器要訪問的地址。瀏覽器要訪問的地址是url,服務器要訪問的是服務器端的相對位置。如:
1.request.getRequestDispatcher("/index.jsp");
2.response.sendRedirect("/day05/form.html");
3.this.getServletContext().getRealPath("/download/日本紐.jpg");
4.this.getServletContext().getResourceAsStream("/download/日本紐.jpg");
5.<a href='/day05/index.jsp'>點點</a>
<form action='/day05/servlet/ResponseDemo1'></form>
<img src='/day05/download/日本紐.jpg'>
一般先在前面打個/,然後看是誰訪問。
注:url用斜槓“/”,磁盤上得目錄用反斜槓"\"