jsp和js中获取项目路径名

一.jsp
a.<%=request.getContextPath()%>//结果:/projectName
b.${pageContext.request.contextPath}//结果:/projectName
用法:
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/order/css/OrderCss.css" />
<link rel="stylesheet" type="text/css" href=<%=request.getContextPath()%>+"/order/css/OrderCss.css" />

二.js
a.‘${pageContext.request.contextPath}‘//结果:/projectName
b.‘<%=request.getContextPath()%>‘//结果:/projectName
用法:
<script>
function searchData(dom){
  $(dom).attr(‘disabled‘, true);
  var url = ‘${pageContext.request.contextPath}/OrderController/getOrders.jsp?‘+$(‘#orderForm‘).serialize();
  var url = ‘<%=request.getContextPath()%>‘+‘/OrderController/getOrders.jsp?‘+$(‘#orderForm‘).serialize();
  $(‘#dataDiv‘).html(‘数据加载中...‘).load(url, function(){
    $(dom).attr(‘disabled‘, false);
  });
}
<script>

原文地址:https://www.cnblogs.com/kl0428/p/9555539.html

时间: 2024-08-29 16:40:08

jsp和js中获取项目路径名的相关文章

js中获取项目路径的小插件

//立即执行的js (function() { //获取contextPath var contextPath = getContextPath(); //获取basePath var basePath = getBasePath(); //将获取到contextPath和basePath分别赋值给window对象的g_contextPath属性和g_basePath属性 window.g_contextPath = contextPath; window.g_basePath = basePa

jsp及servlet中获取项目路径的一些方法

获取项目的路径:1.在实现了servlet接口的实现类中:根据config 调用方法,config.getServletContext().getContextPath(); 2.在一个直接创建的servlet类中(实际上是实现了httpservlet):request.getContextPath(); 3.在jsp中:由九大内置对象的request对象获取.request.getContextPath(); 4.在EL标签中${pageContext.request.contextPath}

jsp在js里获取项目名

function getRootPath() { var curWwwPath = window.document.location.href; var pathName = window.document.location.pathname; var pos = curWwwPath.indexOf(pathName); var localhostPath = curWwwPath.substring(0, pos); //获取带"/"的项目名,如:/hotel var projec

JS中获取数据库中的值

在本次项目中,遇到很多问题,经过努力,都逐步得到解决.静下心来,做一个记录,以供以后学习. 在项目中遇到一个问题,需要在JS中读取数据库中的值,然后再把值返回到页面中,解决方案如下:使用Ajax方法来实现,需要用到ajax.dll(一个ajax技术开发的帮助类库). 实施过程如下: 1.引用Ajax.dll 2.在App_Code写具体的方法,最好单独建立一个类文件,然后写具体方法. public class AjaxMethod www.2cto.com { public AjaxMethod

js中获取时间new date()的用法

js中获取时间new date()的用法 获取时间:   var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份(4位,1970-????) 3 myDate.getMonth(); //获取当前月份(0-11,0代表1月) 4 myDate.getDate(); //获取当前日(1-31) 5 myDate.getDay();

60秒验证码倒计时js代码 js样式代码 方块上下左右随机移动(定时器) js中获取元素的方法 js中表单提交

60秒验证码倒计时js代码 <script type="text/javascript"> var countdown=60; function settime(val) { if (countdown == 0) { //removeAttribute() 方法删除指定的属性. disabled属性规定应该禁用 input 元素. val.removeAttribute("disabled"); val.value="免费获取验证码"

js中获取URL中指定的查询字符串

js中获取URL中指定的搜索字符串,主要利用location对象实现,废话少说,上代码. 1 function getSearchString(key) { 2 // 获取URL中?之后的字符 3 var str = location.search; 4 str = str.substring(1,str.length); 5 6 // 以&分隔字符串,获得类似name=xiaoli这样的元素数组 7 var arr = str.split("&"); 8 var ob

js中获取键盘事件

1 <script type="text/javascript" language=JavaScript charset="UTF-8"> 2 document.onkeydown=function(event){ 3 var e = event || window.event || arguments.callee.caller.arguments[0]; 4 if(e && e.keyCode==27){ // 按 Esc 5 //要

在TFS中获取项目

一.在TFS中获取项目: (1)team (2)connect to team.... (3)选择服务地址,然后close (4)然后映射本地文件夹下载项目 (5)mapped添加映射,在map下就可以了 (6)得到项目文件 二.获取最新 三.上传(迁入)