getServletContext()
request.getRealPath(java.lang.String
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()
获取服务器端口号
本文介绍了Servlet中的关键方法,包括如何使用getServletContext()方法获取servletContext,request.getRealPath()的替代方法ServletContext.getRealPath(),以及request.getContextPath()、request.getScheme()、request.getServerName()和getServerPort()等方法的作用。
302

被折叠的 条评论
为什么被折叠?



