1

I have one jsp say jsp1 page that sometimes need to load independently and sometime I need to do AJAX call to embed that page (simply injecting a whole page with headers) inside my other jsp say jsp2. Both jsp pages have jQuery defined.

But now the issue I am facing is, if I do an AJAX call to include jsp2 inside my jsp1, jQuery is defined twice and causing all sort of issue.

Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
  • 1
    What do you mean "embedded" ? Are you simply injecting a whole page with headers into another one ? Please clarify your question (hint: a question without code is almost always a bad one). – Denys Séguret Oct 30 '17 at 14:54
  • @DenysSéguret yes I am. I edited my question as well –  Oct 30 '17 at 14:56
  • 3
    An HTML document can only have one html tag and one body tag. Your HTML is invalid and the problem you see is only one of the many ones you'll have. You should start by fixing your structure to avoid injecting whole pages (examples of solution: have all pages inject a header part, use an existing framework). – Denys Séguret Oct 30 '17 at 14:57
  • You could opt for layout templates as shown in this tutorial: https://www.javaworld.com/article/2076174/java-web-development/jsp-templates.html. As mentioned by Denys Séguret, you can only have 1 html tag. – karen Oct 30 '17 at 15:03
  • @DenysSéguret Is there a way that I can load only script and body tag via ajax call. –  Oct 30 '17 at 15:07
  • 2
    AJAX is about fetching data, not HTML – Denys Séguret Oct 30 '17 at 15:14
  • Possible duplicate of [check if jquery has been loaded, then load it if false](https://stackoverflow.com/questions/1828237/check-if-jquery-has-been-loaded-then-load-it-if-false) – mrbox Oct 30 '17 at 15:31

0 Answers0