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