1

I need to load a common JS file while loading all JSP pages in my project.Its a third party statistics tracking JS SDK .I need to integrated with my project ,Which contains mixed html and JSP pages.Its difficult to add script tag in all pages mannualy. Any suggession to do it and thanks in advance.

Jamsheer
  • 3,673
  • 3
  • 29
  • 57

3 Answers3

2

If you have used any technologies like tiles or common jsp pages like header footer then it will be one place you need to add. Otherwise no other way you will have to include the script tag in all Jsp pages if you have individual pages.

OR If you have any script file already included in all the file you include your js file in that JS file

Selvakumar Ponnusamy
  • 5,363
  • 7
  • 40
  • 78
  • Nice idea to include js file in existing js. – Mani Jun 02 '16 at 10:27
  • can i do it through filter class by overriding any class ? – Jamsheer Jun 02 '16 at 10:28
  • by using this answer of the link we can include http://stackoverflow.com/questions/2145914/including-a-js-file-within-a-js-file – Mani Jun 02 '16 at 10:30
  • You may go through it. It may help you http://stackoverflow.com/questions/14736328/looking-for-an-example-for-inserting-content-into-the-response-using-a-servlet-f where they have examples for inserting content in servlet filter at run time – Selvakumar Ponnusamy Jun 02 '16 at 10:42
1

by using normal script method you can attach

<script type="text/javascript" src="js/jquery.js"></script>
Mani
  • 2,675
  • 2
  • 20
  • 42
  • 2
    this will add to current jsp only.. he needs to add to all JSPs – Prashant Jun 02 '16 at 10:17
  • create on header.jsp file, in their you put your scripts and include that file in all jsp page. – Mani Jun 02 '16 at 10:19
  • Its dificult to me ,to do the same i need to add script to all my pages.I need to integrate same with more projects – Jamsheer Jun 02 '16 at 10:19
  • In every project try to have one header and footer file. then whatever change you want to do, you can easily access entire website by using single file. – Mani Jun 02 '16 at 10:21
0

Create your header file with script tag and more other common tags. Than include header into your page using:

<%@include file="header.jsp"> 

You can get more information about include here.

HRgiger
  • 2,750
  • 26
  • 37
  • thank you for reply .it can't solve my problem.It recomend to include every pages.I am searching a solution without updating JSP files – Jamsheer Jun 02 '16 at 10:31
  • can i do it through filter class or by overriding any class ? – Jamsheer Jun 02 '16 at 10:33
  • In theory yes you can overwrite the response header with filter using i.e. a RequestDispatcher , but I dont have environment to test it. – HRgiger Jun 02 '16 at 10:46