码迷,mamicode.com
首页 > Web开发 > 详细

jsp 页面获取当前路径

时间:2017-05-07 12:56:50      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:pat   href   ppa   src   request   encoding   var   ext   页面   

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path+"/";
request.setAttribute("realPath", basePath);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">

function getAppPath(){
return "${realPath}";
}

</script>

1.外联路径

<link rel="stylesheet" type="text/css" href="${realPath}css/main.css">

<img src="${realPath}images/face01.png" class="img" id="articleAuthor"> <span id="author"></span>

2.在js调用主机地址

var appPath=getAppPath();

$("#playImage").attr("src", appPath+"images/icon_play.png");

 

jsp 页面获取当前路径

标签:pat   href   ppa   src   request   encoding   var   ext   页面   

原文地址:http://www.cnblogs.com/blogxiao/p/6820286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!