本文实例讲述了jsp获取url路径的方法。分享给大家供大家参考,具体如下:如果你请求的URL是 http://localhost:8080/demo/Index.jsprequest.getScheme() //输出:httprequest.g...
本文实例讲述了jsp获取url路径的方法。分享给大家供大家参考,具体如下:
如果你请求的URL是 http://localhost:8080/demo/Index.jsp
request.getScheme() //输出:http
request.getServerName() //输出: localhost
request.getServerPort() //输出: 8080
request.getContextPath() //输出: /demo
request.getRequestPath() //输出: /Index.jsp
request.gerRequestURI() //输出: /demo/Index.jsp
request.getRequestURL() //输出: http://localhost:8080/demo/Index.jsp
request.getRealPath("") //输出:D:\apache-tomcat-6.0.10\webapps\demo
上面几个我都验证过了,除了request.getRequestPath() 无法使用外(估计这个函数已经被废弃掉了吧),其它的显示都正确。
希望本文所述对大家JSP程序设计有所帮助。
沃梦达教程
本文标题为:jsp获取url路径的方法分析


基础教程推荐
猜你喜欢
- jsp hibernate的分页代码第3/3页 2024-01-11
- 详解http请求中的Content-Type 2023-07-31
- springboot中request和response的加解密实现代码 2022-12-08
- JSP servlet实现文件上传下载和删除 2023-07-30
- SpringBoot嵌入式Web容器原理与使用介绍 2023-06-17
- java 解决Eclipse挂掉问题的方法 2024-01-10
- Spring MVC数据绑定方式 2023-06-30
- 关于@MapperScan包扫描的坑及解决 2023-04-16
- 用javascript制作qq注册动态页面 2023-12-16
- SpringBoot 2.5.5整合轻量级的分布式日志标记追踪神器TLog的详细过程 2023-06-17