Reputation: 11
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?
Upvotes: 1
Views: 2360
Reputation: 2220
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>");
}
}
%>
Upvotes: 1