request.getRealPath(java.lang.String path) 這個方法已經不推薦使用了
Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead.
在JSP中可以這樣用
request.getSession().getServletContext().getRealPath("/") 得到站點的絕對地址
在servlet或者struts中還可以這樣用
this.getServletContext().getRealPath("/");
request.getContextPath()得到的是項目的名字,如果項目爲根目錄,則得到一個"",即空串,
如果項目名爲Test, <%=request.getContextPath()% >/ 將得到Test/。
request.getScheme();
返回的協議名稱,默認是http
request.getServerName()
返回的是你瀏覽器中顯示的主機名
getServerPort()
獲取服務器端口號