basePath = request.getScheme()+"://"+request.getServerName()+":"+r
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
这个语句是用来拼装当前网页的相对路径的。
是用来表明当前页面的相对路径所使用的根路径的。
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do
其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。
有了这个 以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个 ,那么我页面的连链接就必须写全路径,否则服务器会找不到。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog
这四个拼装起来,就是当前应用的跟路径了
最近在自学struts,被里面struts中action 的path与form表单的action属性弄迷糊了。
struts-config.xml 文件中,action元素中的path属性表示的是浏览器地址栏中相对于应用程序根目录的请求路径,与form 中提交表单以后有谁处理的action属性指定的根路径一致。(只是一致,千万不要以为是绝对相等~)
例如:form表单的提交处理请求是classesAdd.do,其在ie地址栏中的路径如下所示,
http://localhost:9000/Struts_study/classesMan/classesAdd.do
红色部分表示的根路径,所以,action中的classesAdd.do请求的完整路径是classesMan/classesAdd.do
所以 struts 中的action 的path路径是指/classesMan/classesAdd。
大家可以看着浏览器的地址栏加以配置。祝大家晚上睡觉快乐。
补充一下吧,form中的action的默认路径就是当前路径,
而struts中的action 的path属性默认路径为根路径,所以要加上所在的文件夹得路径。
basePath = request.getScheme()+"://"+request.getServerName()+":"+r的更多相关文章
- String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+pat----------<base>元素有关
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. ...
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer
这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080.具体点: ...
- jsp页面String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!
转自:https://blog.csdn.net/kiwangruikyo/article/details/81130311 <%String path = request.getContext ...
- 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...
- JSP中的:request.getScheme()+"://"+request.getServerName()+":"+request.getServer
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+reque ...
- request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/"
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+reques ...
随机推荐
- 【HDU 2063】过山车(二分图匹配)
n个女生,m个男生.如果女生i愿意让男生j作为parner,那就建边i->j+n,和j+n->i.然后用匈牙利算法算出最大匹配. 要注意N和M都要开2倍. #include <cst ...
- Maven报错: Missing artifact jdk.tools:jdk.tools:jar:1.7
pom.xml 有小红叉,报错: Missing artifact jdk.tools:jdk.tools:jar:1.7 解决方法:(缺少一个jar包) http://blog.csdn.net/u ...
- [bzoj3694]最短路
Description 给出一个$n$个点$m$条边的无向图,$n$个点的编号从$1-n$,定义源点为$1$. 定义最短路树如下:从源点$1$经过边集$T$到任意一点$i$有且仅有一条路径,且这条路径 ...
- hadoop报错:WARN mapred.JobClient: Error reading task outputNo route to host
解决方案: /etc/sysconfig/network/etc/hosts$hostname 这三处的主机名都要一样. 具体参考:http://blog.itpub.net/28254374/vie ...
- 【poj1984】 Navigation Nightmare
http://poj.org/problem?id=1984 (题目链接) 题意 给出一棵树,这棵树是以平面直角坐标系为基准建立的,也就是每个节点最多只有上下左右4条边.现在动态建树,同时询问两点间的 ...
- 贴一段shell代码
好久没用shell了,呵呵,这个是当counter < 1000的时候,往tmp.sql里填这两个字符串,生成假数据. #!/usr/bin/env bash COUNTER= ]; do ec ...
- PHP中的一个”坑“
说一个极有可能在工作中遇到的问题——foreach的引用 foreach $arr = range(1,3); //[1,2,3] foreach($arr as &$val) { } for ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- Alpha版本十天冲刺——Day 2
站立式会议 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 学习post请求连接服务器,学习git 无 http资源请求方法封装,完成Android验证码获取接口和登录验证接口 今天满课, ...
- Beta版本——第七次冲刺博客
我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...