iframe javascript:location.replace(url)路径问题
来源:互联网 发布:淘宝做家纺上货视频 编辑:程序博客网 时间:2024/06/06 03:51
最近做Struts2项目,做登陆验证的拦截器时遇到一个小问题:
我在我的一个a.jsp中写了这么一句:
parent.location.href("login.jsp");
但是当我的a.jsp在webRoot或者和我的login.jsp在同一级目录下时,就没有问题;
但是如果我的a.jsp在a/a.jsp,login.jsp在webRoot下时,此时url为http://localhost:xxxx/SSM/a/a.jsp时,
执行完parent.location.href("login.jsp");我期望的url会访问到我SSM/login.jsp;
但是结果url是SSM/a/login.jsp;即使我在a.jsp中写了
<span style="font-size:14px;"><%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%><%<span style="white-space:pre"></span>String path = request.getContextPath();<span style="white-space:pre"></span>String basePath = request.getScheme() + "://"<span style="white-space:pre"></span>+ request.getServerName() + ":" + request.getServerPort()<span style="white-space:pre"></span>+ path + "/";%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><base href="<%=basePath%>"></span>也没有用,我记得其他页面中如果指定了basePath后,页面中所有用的相对路径的地方,都会自动的是相对于basePath根路径了(类似绝对路径)。
但是感觉这个location.href好像丝毫不起作用。
同时在jsp中,我们知道相对路径是相对于客户端url的路径,而不是相对于服务器的路径的。
“/”是表示web的根路径,即tomcat下;如果在jsp中庸parent.location.href("/login.jsp");则会定位到tomcat下的index.jsp中,
这也是我们不希望的,所有只有使用终极方式绝对路径
即:parent.location.href("${basePath}index.jsp");
同时这种方式也避免了对于不同浏览器的兼容问题,因为不同的client解析location.href的方式不同,出来的路径也不一样。
但是用这种方式就避免了那些问题。
0 0
- iframe javascript:location.replace(url)路径问题
- JS:location.replace(url)
- window.location.replace("url")不执行
- window.location.reaload (true) (false) window.location.replace(url)
- window.location.assign(url)和replace(url)区别
- 【JavaScript】页面刷新location.reload和location.replace的区别
- window.location方法获取URL;window.location.assign(url)和replace(url)区别
- window.location方法获取URL及window.location.assign(url)和replace(url)区别
- js用 window.location.href跳转IE和chrome中路径url不一致问题
- javascript iframe跳转问题
- location.herf 和 location.replace
- javascript中history.go(),history.back(),location.reload()和location.replace区别
- javaScript中location.reload()方法和location.replace()方法的区别
- URL路径长度问题
- angular location replace
- 28. Location replace() 方法
- js location.replace()
- js获取当前Url网址路径及参数 location.hostname
- @Autowired 与@Resource的区别:
- springmvc 返回@ResponseBody (一key多value)以及IE兼容
- 如何做好网站导航的布局优化?
- hadoop streaming部分问题总结
- 分享一个链接
- iframe javascript:location.replace(url)路径问题
- 带外管理简述
- 我常常浏览的博客和网站
- linux开启user_cmd功能记录用户所有操作指令到log message中
- <html>标签
- Git基本命令使用
- 通过变量名获取变量值
- .docx 读与写
- iosios属性关键字