0

I have a JSP file that gives me a bunch of JS code that I need to put in my view page (particularly in my JSP file that is the view for the current URL. Using Spring MVC) . Is there a way for it?

I have already tried a bunch of suggestions from here: Including JSP code from another JSP file correctly and here https://coderanch.com/t/596663/frameworks/Calling-jsp-include-tag-javascript but none gives clear answer on it. When the view is rendered after hitting the controller it just gave a plain JS code in the window instead of embedding it as JS code.

    <html>
    <head> </head>
    <script type="text/javascript">
        <jsp:include page="./myJSPfiles/MyJSPfileforScript" />
    </script>
</html> 

As I said, it just gives plain JS code in the browser instead of embedding it. I am fairly new to JSPs in general. Any suggestions?

brutle
  • 1

1 Answers1

0

Use something like below line of code.

<script type="text/javascript" src="${pageContext.request.contextPath}/js/index.js"></script>
Alien
  • 15,141
  • 6
  • 37
  • 57
  • I am able to access my file by simply using its path( as in code above) , the problem is that JS code provider is not a JS file but a JSP one – brutle Jul 11 '19 at 06:18