二十五、request,其他操作方法
取得路径名称(上下文路径):进行资源定位
public String getContextPath()
---------
<%@ page pageEncoding="UTF-8"%>
<%
String contextPath=request.getContextPath();
%>
<h1><%=contextPath%></h1>
输出整个虚拟目录的映射路径
在任何一个JSP页面里面都可能会引入其他的文件
<%@ page pageEncoding="UTF-8"%>
<%
String contextPath=request.getContextPath();
%>
<h1><%=contextPath%></h1>
<img src="<%=contextPath%>/images/img.jpg" height="30%">
在HttpServletRequest接口里面还提供有一些取得其他信息的方法:
**取得IP地址:public String getRemoteAddr()
**取得协议模式:public String getScheme()
**取得服务器名字:public String getServerName()
**取得访问端口:public int getServerPort()
取得基本信息:
String contextPath=request.getContextPath();
//完整路径
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath;
资源访问一定要用绝对路径
request对象存在有属性操作,但是属性操作与参数操作没有关联