JSP-----------request,其他操作方法

二十五、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对象存在有属性操作,但是属性操作与参数操作没有关联

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值