javascriptjspline-breaksjspinclude

jsp include file without line breaks


I have the following line of javascript code:

element.innerHTML = '<%@include file="../jsp/welcome.jsp" %>';

Everything would work fine if the welcome.jsp file is written in one line. But as the file contains line breaks then the javascript code is broken because there are line breaks between the apostrophes like this:

element.innerHTML = '
<p>
...
</p>
';

Can anyone know how to easily include jsp files without line breaks? I know I can remove all the line breaks manually but it would be quite annoying to me and it will be challenging to continue with development on "one-line" pages.

Thanks.


Solution

  • This task can be partialy done by using backslashes:

    element.innerHTML = `<%@include file="../jsp/welcome.jsp" %>`;
    

    But it won't work in every case e.g. when you use backslashes in the innerHTML page.