惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
Y
Y Combinator Blog
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
P
Proofpoint News Feed
Jina AI
Jina AI
B
Blog RSS Feed
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
D
Docker

博客园 - wj-conquer

Oracle数据库管理员面试题 dl, dt, dd标签的使用方法 新年到了, 写了几个网页祝福大家新年快乐, 万事如意 java根据自定义标记分割字符串 word2007中批量添加超链接的方法 如何使用freemarker将jsp网页静态化? 百度广告联盟号被封 网站被降权 SQLServer如何取得随机获取的数据库记录 IE出问题,所有网页提示脚本错误 CSS使文章自动换行的问题 很精美的仿京东商城产品详细JS放大效果 JSP面试题及答案 四大方法提升百度联盟点击率 Java中随机数生成, Manth和Random的用法 在页面中显示系统当前时间,在页面中加载时间 Unable to load configuration. - bean struts-default.xml struts2中的jar包冲突 设置首页 加入收藏代码 百度搜索引擎的代码、百度搜索功能的码代 Java调用SQL Server存储过程同时返回参数和结果集
jsp获取相对路径网址的方法 request.getContextPath()
wj-conquer · 2012-11-08 · via 博客园 - wj-conquer

1. 在jsp页面中取得网站的首页的路径

<%
 String appContext = request.getContextPath();
 Integer prot=request.getServerPort();
 String basePath ="";
 if(prot==80)   //80为默认端口
  basePath = request.getScheme()+"://"+request.getServerName()+ appContext;
 else
  basePath = request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort() + appContext;
%>

2. 在超链接中的写法

<a title="首  页" href="<%=basePath %>" target="_self">首  页</a>

<a title="美体" href="<%=basePath %>/fat"   target="_self">美体</a>

3. 在浏览器html中显示的为:

<a title="首  页" href="http://www.txw100.com" target="_self">首  页</a>

<a title="美体" href="http://www.txw100.com/fat"   target="_self">美体</a>