简体   繁体   中英

include all js files under a folder in jsp

Can we include all js files in one folder in jsp page. For example i had a folder name with ABC and js files under it is a.js, b.js and c.js.Instead of including js files individually in jsp page

<script type="text/javascript" src="<%=request.getContextPath()%>/ABC/a.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/ABC/b.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/ABC/c.js"></script>

can we do like below format ???

<script type="text/javascript" src="<%=request.getContextPath()%>/ABC/*.js"></script>

I mean i need to include all 3 js files in jsp page. can anyone help?

Something like this should work:

<%
for(File f : new File(request.getContextPath() + "js").listFiles()){
  if(f.getName().endsWith(".js")){
     out.println("<script src='js/" + f.getName() + "' type='text/javascript'></script>");
  }
}
%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM