【JSP中引入文件】JSP中获取根路径+引用js文件

在jsp界面中经常需要引入js、css等文件,通常都需要先获取项目根路径,然后再引入文件。
例如:
项目路径如下,需要在index.jsp中引入FusionCharts相关的js、css等;
【JSP中引入文件】JSP中获取根路径+引用js文件


index.jsp

  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  5. response.setHeader("Pragma", "no-cache");
  6. response.setHeader("Cache-Control", "no-cache");
  7. response.setDateHeader("Expires", 0);
  8. %>
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html>
  11. <head>
  12. <title>My first FusionCharts</title>
  13. <script type="text/javascript" src="<%=basePath%>fusionCharts/fusioncharts.js"></script>
  14. <script type="text/javascript" src="<%=basePath%>fusioncharts/themes/fusioncharts.theme.fint.js"></script>
  15. <link rel="stylesheet" type="text/css" href="<%=basePath%>css/uploadify.css"/>
  16. <script type="text/javascript"></script>
  17. </head>
  18. <body></body>
  19. </html>






上一篇:linux stat命令


下一篇:Hibernate中Entity实体类的写法