JSP document changing script element

Discussion in 'Java' started by jsguru72, Sep 5, 2008.

  1. jsguru72

    jsguru72 Guest

    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
    jsguru72, Sep 5, 2008
    #1
    1. Advertising

  2. jsguru72

    Dave Miller Guest

    jsguru72 wrote:
    > 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.

    --
    Dave Miller
    Java Web Hosting
    http://www.cheap-jsp-hosting.com/
    Dave Miller, Sep 5, 2008
    #2
    1. Advertising

  3. jsguru72

    jsguru72 Guest

    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.
    jsguru72, Sep 5, 2008
    #3
  4. jsguru72

    Dave Miller Guest

    Lew wrote:
    > jsguru72 wrote:
    >> ----------
    >> <?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"/>

    >
    > 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.

    --
    Dave Miller
    Java Web Hosting
    http://www.cheap-jsp-hosting.com/
    Dave Miller, Sep 6, 2008
    #4
  5. jsguru72

    Dave Miller Guest

    jsguru72 wrote:
    > 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

    --
    Dave Miller
    Java Web Hosting
    http://www.cheap-jsp-hosting.com/
    Dave Miller, Sep 6, 2008
    #5
  6. jsguru72

    jsguru72 Guest

    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.
    jsguru72, Sep 6, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    1
    Views:
    344
    Sudsy
    Jul 2, 2004
  2. Andy Fish
    Replies:
    1
    Views:
    698
    Martin Honnen
    Jul 2, 2004
  3. Replies:
    0
    Views:
    4,332
  4. HANM
    Replies:
    2
    Views:
    696
    Joseph Kesselman
    Jan 29, 2008
  5. Brian
    Replies:
    2
    Views:
    216
Loading...

Share This Page