jsp 页面获取当前路径
Posted blog_xiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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");
以上是关于jsp 页面获取当前路径的主要内容,如果未能解决你的问题,请参考以下文章