JSP中的:request.getScheme()+://+request.getServerName()+:+request.getServer
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href=" <%=basePath%>">
<base href="...">是用来表明当前页面的相对路径所使用的根路径的。
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do
其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。
有了这个 <base ... >以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 <base ...>指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个 <base...>,那么我页面的连链接就必须写全路径,否则服务器会找不到。
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
<form name="form1" action="classesAdd.do" method=post>
所以 struts 中的action 的path路径是指/classesMan/classesAdd。
大家可以看着浏览器的地址栏加以配置。祝大家晚上睡觉快乐。
补充一下吧,form中的action的默认路径就是当前路径,
而struts中的action 的path属性默认路径为根路径,所以要加上所在的文件夹得路径。
使用方法如:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>404</title> <meta http-equiv="refresh" content="60;url=index.jsp"> <!-- content="600,即600秒后返回主页,可根据需要修改或者删除这段代码 --> <link href="css/error.css" rel="stylesheet" type="text/css" /> </head> <body> <!-- 代码 开始 --> <div id="container"><img class="png" src="data:images/404.png" /> <img class="png msg" src="data:images/404_msg.png" /><p><a href="index.jsp"><img class="png" src="data:images/404_to_index.png" /></a> </p> </div> <div id="cloud" class="png"></div> <!-- 代码 结束 --></body> </html>
JSP中的:request.getScheme()+://+request.getServerName()+:+request.getServer相关推荐
- jsp中String path = request.getContextPath()的作用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- basePath = request.getScheme()+://+request.getServerName()+:+r
basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...
- JSP中Request属性范围
JSP属性范围,通过以下几个测试代码来学习request属性的范围 测试一(JSP动态指令方式传参): 测试内容: <jsp:param .../>添加参数,通过<jsp:forwa ...
- jsp中接收java的返回值_jsp中request的一些方法返回值
在页面上打印如下内容,通过服务器本地和客户端异地调用的结果如下 String url111 = request.getRequestURI(); System.out.println("ur ...
- JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,respon 区别
JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳转,但是 ...
- Jsp中request.getParameter(@param)值为[object HTMLInputElement]
Jsp中request.getParameter("@param")值为[object HTMLInputElement] jsp窗体之间传递参数是常有的.一般窗体传参就是从一个窗 ...
- 新手入门:介绍JSP中request属性的用法
新手入门:介绍JSP中request属性的用法 一.request.getParameter() 和request.getAttribute() 区别 (1)request.getParameter( ...
- JAVA中的request用法_新手入门:介绍JSP中request属性的用法
一.request.getParameter() 和request.getAttribute() 区别 (1)request.getParameter()取得是通过容器的实现来取得通过类似post,g ...
- jsp中request对象的用法
1.request介绍 用户发送的所有的请求都是通过request对象实现,request中携带了请求的地址.参数等等 2.request对象的方法介绍 方法名 描述 getParameter(Str ...
最新文章
- adb.exe: device offline
- Apollo之灰度发布
- ubuntu ftp服务器搭建,绝对有效,操作简单
- 将SVG 图引入到HTML页面
- effective C++ 条款 3:尽可能使用const
- Gartner Q2服务器市场报告5大要点
- 【java小知识】FileReader读取文件出现乱码的解决办法
- 单元测试——Winfrom
- vue —— UI组件库
- 程序员如何应对诸如“给我弄个网站吧”的请求?
- python类的构造函数是_python类(class)的构造函数、初始化函数、析构函数
- 从零开始学Kotlin-类的继承(6)
- java.lang.OutOfMemoryError: PermGen space---先测试
- 固定资产中计算机软件类型,固定资产国标分类1.doc
- DNS域名解析服务介绍
- java木马源码_用Java编写木马程序【附源代码下载】
- liunx开启Nginx失败, 出现 An error occurred
- 公司寄件管理平台必要性分析
- 根据 Excel 数据表的内容和 Word 模板文件,批量生成 Word 文档
- Dilated Convolutions——扩张卷积
热门文章
- gitmaven命令
- leetcode704. 二分查找
- redis——实战点赞
- redis——数据结构(整数集合,压缩列表)
- 深度学习(11)-- GAN
- 《C++ Primer 5th》笔记(7 / 19):类
- mysql 5.5.23 winx64,win10下mysql 5.7.23 winx64安装配置方法图文教程
- c++面向对象高级编程 学习十五 组合继承关系下的构造和析构
- 三十功名尘与土——资深程序员生涯自白
- OpenCL用于计算机领域的13个经典案例