Announcement Announcement Module
Collapse
No announcement yet.
Jspx pages as views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jspx pages as views

    Hi,

    I was wondering if anybody had problems with using .jspx pages as views in Spring? I'm just using a really simple example to see if I can get it to work:

    information.jsp:
    Code:
    <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http&#58;//java.sun.com/jstl/fmt" %>
    <%@ taglib prefix="str" uri="http&#58;//jakarta.apache.org/taglibs/string-1.1" %>
    <%@ taglib prefix="spring" uri="/spring" %>
    
    <html>
    <body>
    	<c&#58;out value="hello"/>
    </body>
    </html>
    information.jspx:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <html 
     xmlns&#58;c="http&#58;//java.sun.com/jsp/jstl/core"
     xmlns&#58;dpe="urn&#58;jsptagdir&#58;/WEB-INF/tags/DPE/"
     xmlns&#58;jsp="http&#58;//java.sun.com/JSP/Page"
     xmlns="http&#58;//www.w3.org/1999/xhtml">
     
     <jsp&#58;directive.page 
          pageEncoding="ISO-8859-1" 
          contentType="text/html; ISO-8859-1" />
    
    	<c&#58;out value="hello"/>
    </html>
    To my knowledge, these two pages should give the same output. But they don't. The .jsp page gives the expected output ("hello"), but the .jspx page gives me an empty page, where I can find <c:out value="hello"/> in the source code. Btw, my url-pattern for the DispatcherServlet in web.xml is "*.htm".

    Is this expected behaviour from Spring's side? Has anyone seen something similar before and can help me out with a solution? My best bet so far is rewriting about twenty .jspx and.tagx files to "normal" jsp, something that doesn't seem too tempting.

  • #2
    I know someone that had similar issues but can't remember what the solution was. I notified him and hope he'll be answering soon...

    rgds,
    Alef Arendsen

    Comment


    • #3
      Thanks a lot, that would be real helpful.

      Comment


      • #4
        The fact that the page is in the source, and not rendered, tells me that the encoding type is probably wrong.

        I'm assuming you use Firefox, or at least have it installed. Grab the plugin liveHttpHeaders (http://livehttpheaders.mozdev.org/), and you can confirm or deny this theory.

        As for why the encoding type would be wrong when you're obviously setting it correctly in your JSP, I'm not sure. I'm very new to Spring, but I guess first I'd make sure they work ok without Spring in the picture, and then I'd start looking for places that Spring would set the encoding type.

        --James

        Comment


        • #5
          How are you referencing the jspx file? Usually jspx are fragments which are included in another file? Do you have a view mapped which uses the jspx file directly?

          What does your web.xml look like?

          Comment


          • #6
            jspx pages

            keibi

            I'm using .jspx pages for my views - your problem seems curiously familiar, but annolyingly I cannot remember the specific case or configuration that caused .jspx content not to render. I don't think this problem is related to Spring, rather your JSP/Servlet code or configuration.

            Firstly a basic question...what JSP version are you using? Is it JSP 2.0? The JSP syntax you used is for JSP 2.0.

            I put together a test page based on your .jspx example - this looks as follows:

            Code:
            <?xml version="1.0" encoding="ISO-8859-1"?>
            <html
             xmlns&#58;c="http&#58;//java.sun.com/jsp/jstl/core"
             xmlns&#58;jsp="http&#58;//java.sun.com/JSP/Page"
             xmlns="http&#58;//www.w3.org/1999/xhtml">
            
            	<jsp&#58;output doctype-root-element="html"
                    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
                    doctype-system="http&#58;//www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
                <jsp&#58;directive.page contentType="text/html;charset=ISO-8859-1" />
                
             <body>
               <c&#58;out value="hello"/>
             </body>
             
            </html>

            Some things to note:

            1. This page uses a jsp:output tag to generate the DOCTYPE declaration for the page. This will help the browser identify how your page should will be rendered.

            2. I don't know if this is what you're intending, but your .jspx page is generating an XHTML document - in comparison, your .jsp page is generating an HTML page.

            Just to make your life more colourful, xhtml is not fully supported by all browsers (notably Internet Explorer...who'd have guessed!!!). I don't think that this is the root cause of your problem (the above example generates an XHTML page), but it adds another dimension to the problem.

            To generate a HTML DOCTYPE, use the following:

            a) 'xmlns="http://www.w3.org/1999/html"' instead of 'xmlns="http://www.w3.org/1999/xhtml"'

            and

            b) <jsp:output doctype-root-element="html"
            doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
            doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>

            3. Your .jspx page is missing a <body> tag - I guess that it didn't quite make it into your code example . If your target browser is very fussy, this might prevent anything from being displayed. (Again probably not the root cause of the problem.)


            Otherwise, you might want to check your web.xml file to make sure that you don't have a jsp-property-group element that explicitly tells the web container not to treat .jspx files as a JSP Document.

            Comment

            Working...
            X