JSP开发 路径问题汇总

//第一种 jsp 表达式
<%=request.getContextPath %>
获取到 web项目名的绝对路径

<!--使用绝对路径的方式引入CSS文件-->
<link rel="stylesheet" href="${pageContext.request.contextPath}/themes/default/css/ueditor.css" type="text/css"/>
<!--使用绝对路径的方式引入JavaScript脚本-->
<script type="text/javascript" src="${pageContext.request.contextPath}/ueditor1_3_6-gbk-jsp/ueditor.config.js"></script>


//第二种
${pageContext.request.contextPath}
获取到 web项目名的绝对路径


//第三种
<%
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<a href="<%=basePath%>upload.jsp">上传 <% out.print( basePath+"upload");%></a></strong><br>
可以直接这么使用

//其他路径问题:
String path = this.getServletContext().getRealPath("/WEB-INF/upload")
获取web-inf 文件夹 路径,没有访问权限,个人理解是网站不能直接访问到服务器的这个文件夹内容,保证安全
posted @ 2017-11-04 15:52  言非言  阅读(116)  评论(0)    收藏  举报