jsp html访问路径,如何解决项目中jsp访问路径的问题

jsp访问路径的解决方法可通过EL表达式、jsp中的java语言所提供的方法、DHTML.js所提供的方法等

如源代码所示:

pageEncoding="UTF-8"%>

/p>

"http://www.w3.org/TR/html4/loose.dtd">

jsp访问路径

jsp访问路径的解决方法

方法一:通过EL表达式获取路径值

method one(EL):

${header['host']}${pageContext.request.contextPath}

方法二:通过DHTML.js里提供的方法(创建javaee项目时,js插件默认已有)

方法三:通过jsp中的java语言

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+

":"+request.getServerPort()+path+"/";

%>

method three(java):

function  load(){

var curPath = window.document.location.href;

var pathName = window.document.location.pathname;

var port = window.document.location.port;

var hostname = window.document.location.hostname;

var host = window.document.location.host;

$("#p_id").html("method two(js):"+

"
curPath:"+curPath+ //访问当前界面绝对路径

"
pathName:"+pathName+  //从项目名开始算起

"
port:"+port+  //tomcat部署的端口号

"
hostname:"+hostname + //主机名和端口号

"
host:" + host);//主机名

}

picture:

08efb4ff634044fa3175f7f1266c471f.png

Methods in DHTML.js:

bdd493d88edbe63a1ff89e99f899edd8.png

其中

/**

@type {string} 使用注解声明string类型

*/

Location.prototype.hostname = null; //对应window.document.location.hostname;

注:方法是多种多样的,不管采用哪种,只要能解决jsp访问路径的问题即可(若要对应自己的项目路径,建议可通过String所提供的分割或替换的方法处理)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值