Java/JavaScript获取URL

来源:互联网 发布:剑灵灵剑捏脸数据图 编辑:程序博客网 时间:2024/05/17 20:12

Java中request对象获取URL及参数

//示例 http://127.0.0.1:8080/urltest/geturl.htm?id=456&no=123request.getScheme()//请求协议->http 或 httpsrequest.getRequestURL()//获取完整无参数的URL->http://www.sun.com/urltest/geturl.htmrequest.getRequestURI()//部分URL->/urltest/geturl.htmrequest.getContextPath()//项目名称->/urltestrequest.getServletPath()//请求地址->/geturl.htmrequest.getQueryString()//获取参数->id=456&no=123           

JavaScript获取URL

//示例 http://127.0.0.1:8080/urltest/geturl.htm?id=456&no=123window.location.pathname//设置或获取对象指定的文件名或路径window.location.href//设置或获取整个URL(字符串)window.location.port//设置或获取与URL关联的端口号window.location.protocol//设置或获取URL的协议window.location.hash//设置或获取href属性中"#"后面的内容window.location.host//设置或获取location或URL的hostname和port号window.location.search//获取URL参数
0 0
原创粉丝点击