jsp 页面获取当前路径

<%@ 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");

 

posted @ 2017-05-07 11:33  zero_and_one  阅读(1057)  评论(0编辑  收藏  举报