JSP document changing script element

J

jsguru72

In my JSP document, I have the following script element defined.
<script type='text/javascript' src='/include/scripts/menu-
row.js'> </script>


Yet, when I load the page in a browser and view the page source I get
the following.
<script type='text/javascript' src='/include/scripts/menu-
row.js'/>


Since the script element does not support the inline syntax,
everything after this element is interpreted as a script instead of
how it should be.


I am using Tomcat 6.0.18

Here is the full JSP document.
----------
<?xml version="1.0" encoding="UTF-8" ?>

<jsp:root version="2.1"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core">

<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>

<html>
<head>
<script type='text/javascript' src='/include/scripts/menu-
row.js'> </script>
</head>
<body>
Random text
</body>
</html>
</jsp:root>
----------


This is the output when I view the page source in a browser.
----------
<html>
<head>
<script src="/include/scripts/menu-row.js" type="text/
javascript"/>
</head>
<body>
Random text
</body>
</html>
----------


Does anyone have any idea where this conversion from the <script></
script> syntax to the <script/> syntax is being done and why?


Thanks
 
D

Dave Miller

jsguru72 said:
In my JSP document, I have the following script element defined.
<script type='text/javascript' src='/include/scripts/menu-
row.js'> </script>


Yet, when I load the page in a browser and view the page source I get
the following.
<script type='text/javascript' src='/include/scripts/menu-
row.js'/>


Since the script element does not support the inline syntax,
everything after this element is interpreted as a script instead of
how it should be.


I am using Tomcat 6.0.18

Here is the full JSP document.
----------
<?xml version="1.0" encoding="UTF-8" ?>

<jsp:root version="2.1"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core">

<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>

<html>
<head>
<script type='text/javascript' src='/include/scripts/menu-
row.js'> </script>
</head>
<body>
Random text
</body>
</html>
</jsp:root>
----------


This is the output when I view the page source in a browser.
----------
<html>
<head>
<script src="/include/scripts/menu-row.js" type="text/
javascript"/>
</head>
<body>
Random text
</body>
</html>
----------


Does anyone have any idea where this conversion from the <script></
script> syntax to the <script/> syntax is being done and why?


Thanks
It's Tomcat apparently because of your jsp:root declaration.
 
J

jsguru72

I am still not clear as to what is actually doing this.

I have done some additional testing and found that this only happens
when using a JSP document (XML). If I do this in a plain JSP page or
in an HTML page, then it all works fine and the script element is sent
to the browser as I entered it.

Should I not be using a jsp:root declaration? All of the
documentation I see shows that as the root element.

Any idea what in Tomcat would be doing this? Do I need to edit some
configuration?

I am drawing a blank so guidance is appreciated.

Thanks.
 
D

Dave Miller

Lew said:
I'm not so familiar with this, but what happens if you change
'contentType' to "text/xhtml"?
No joy - it just causes the browser to look for a helper.
 
D

Dave Miller

jsguru72 said:
I am still not clear as to what is actually doing this.

I have done some additional testing and found that this only happens
when using a JSP document (XML). If I do this in a plain JSP page or
in an HTML page, then it all works fine and the script element is sent
to the browser as I entered it.

Should I not be using a jsp:root declaration? All of the
documentation I see shows that as the root element.

Any idea what in Tomcat would be doing this? Do I need to edit some
configuration?

I am drawing a blank so guidance is appreciated.

Thanks.
Like Lew, I'm no expert in this area.

You're providing an empty js declaration and the jsp:root element causes
the container to rewrite it. If you put code within the js declaration,
it does not change it:

http://www.cheap-jsp-hosting.com/testpage.jsp

Long story short, it appears that you'll need to make your js
declaration compliant, a good place to start learning how is here
(jsp:root shows about 3/4 of the way down):

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPX3.html
 
J

jsguru72

I looked through that tutorial and I am trying to see where it says
the jsp:root element is rewriting the empty script element.

Regardless, your comment about it being an empty declaration prompted
me to insert a random character to the script element, I added a
hyphen. So now my script element has this.
<script type='text/javascript' src='/include/scripts/menu-row.js'> - </
script>

It works perfectly. I had previously thought it was something along
these lines and just put a space between the tags, but I guess I
needed to have a non-whitespace character.

I obviously have a few things to learn about JSP documents. I will
read the tutorial you listed more thoroughly and see what other
information I can dig up.

Thanks for you help in getting me back on track.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top