1

I have Spring MVC application with JSP as view technology. I have included some js, css, taglibs in header part of each and every JSP.

Please note that I have declared taglibs at top of my JSP file above html tag. Can I move all these commons files(.js, .css, taglibs etc) into one file and then include this single file into all my JSPs ?

Considering all above points what will be the best option ?

Please advise.

Peter
  • 185
  • 6
  • 21
  • Take a look at some of the techniques mentioned in [this post](http://stackoverflow.com/a/3257426/1291150) to separate common parts of your JSPs. – Bohuslav Burghardt Oct 17 '15 at 10:49

1 Answers1

0

The best option would be to use a template framework, for example Tiles or Freemaker.

If you still want include your files on your own, you can use "include" directive. Create a JSP page with all commons imports (css, scrips, taglibs declarations, etc..) and then put this directiva on the top of every other page.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/jsp/comun/myCommon.jsp"%>
(... the rest of your page ...)
Sisifo
  • 91
  • 3
  • I have two question here : (1) In myCommon.jsp , you have just put taglibs,js, css statements ? (2) where we need to include this myCommon.jsp , above html tag, because generally we say that css, js should be in head tag. ? – Peter Oct 18 '15 at 04:45
  • Indeed css should go in the head, although with js is not mandatory. I did not realize about this. So, you should create some kind of commond structure like [include common.jsp] [all your stuff]. In fact, this is what tiles would do for you – Sisifo Oct 18 '15 at 10:38