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 ...
随机推荐
- Entity Framework Code First (六)存储过程
声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...
- 100114D
这道题用暴力水过了,蒟蒻是这么想的:枚举两个端点,找最小值,因为shift只能用一次,但是这样10^9*2.5要t,所以减掉只有一个黑点的情况,然后复杂度变为10^9*0.6 #include< ...
- hibernate-DetachedCriteria实现关联表条件复查
表结果如下 CREATE TABLE `ent_lable` ( `idStr` ) NOT NULL, `pk_1` ) NOT NULL, `pk_2` ) NOT NULL, PRIMARY K ...
- Js-加密
1.base64加密 在页面中引入base64.js文件,调用方法为: <!DOCTYPE HTML> <html> <head> <meta charset ...
- Json-遍历
1.js遍历 var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13} ...
- xml解析工具-jdom
前言:近期接触SSH框架的时候,经常得配置一下xml文件:今天闲来没事就挖挖xml解析的原理供大伙儿分享.本文主要通过一个简单的例子解析一个xml文件.明白其中缘由之后,大家想定义自己的xml也绝非难 ...
- bzoj 3172 AC自动机
初学AC自动机,要先对于每一个模式串求出来trie树,在此基础上构建fail指针,然后在trie树加上失配边构建出整张trie图. AC自动机的原理和KMP差不多,一个节点的fail指针就是指向tri ...
- 【BZOJ-2177】曼哈顿最小生成树 Kruskal + 树状数组
2177: 曼哈顿最小生成树 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 190 Solved: 77[Submit][Status][Discu ...
- jdbc/ojdbc连oracle的三种方式(转)
文章转自:http://blog.itpub.net/22664653/viewspace-1383092/ 前言 本文是一篇学习笔记,学习如何通过java jdbc /ojdbc 连接oracle ...
- Android成长日记-ViewPager的使用
ViewPager在安卓应用中主要用于作为程序的引导页面,欢迎页面,以及其他的动画效果,下面将给你讲述ViewPager的使用 在Android3.0以上的Api中,提供了ViewPager的接口,所 ...
转载▼