ssslinppp

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
在jsp界面中经常需要引入js、css等文件,通常都需要先获取项目根路径,然后再引入文件。
例如:
项目路径如下,需要在index.jsp中引入FusionCharts相关的js、css等;



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>










posted on 2015-05-22 12:34  ssslinppp  阅读(1429)  评论(0编辑  收藏  举报