3 Replies Latest reply on Jan 31, 2007 4:54 PM by Erik Hansen

    JSPs shown as text in Firefox (Content-Type: text/plain)

    Mick Dudley Newbie

      Hi I have
      XServlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5

      using mod_jk to attach Apache all works JSP gets compiled and executed.
      But the Content-Type is text/plain but should be text/html and this makes firefox show the jsp html as text.
      IE seems to get it correct, must ignore the Content-Type.

      Any ideas?

      Thanks

        • 1. Re: JSPs shown as text in Firefox (Content-Type: text/plain)
          Erik Hansen Newbie

           

          "bassman5" wrote:
          Hi I have
          XServlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5

          using mod_jk to attach Apache all works JSP gets compiled and executed.
          But the Content-Type is text/plain but should be text/html and this makes firefox show the jsp html as text.
          IE seems to get it correct, must ignore the Content-Type.

          Any ideas?

          Thanks


          I believe you're correct in assuming that IE is ignoring the content-type -- which is an IE bug. It's particularly painful because it masks problems with servers sending the wrong content-type. Unfortunately, 90% of the world will tell you, "works for me."

          I'd be interested in knowing why the pages are served as plain/text, too as I am having the same problem with Apache->mod_jk->JBoss 4.0.5GA/jbossweb-tomcat55->axis2-1.1.1


          • 2. Re: JSPs shown as text in Firefox (Content-Type: text/plain)
            Mick Dudley Newbie

            I found my problem, I used
            RequestDispatcher dispatcher = context.getRequestDispatcher("/mypage.jsp");
            dispatcher.include(request, response);

            Which although the jsp had a content type, it was not set in the response.
            So I added
            response.setContentType("text/html");
            and that sorted it.

            I later restructed my code to only include a single jsp and changed it to :-

            request.getRequestDispatcher("/mypage.jsp").forward(request,response);

            That works as expected.

            Hope that helps.

            • 3. Re: JSPs shown as text in Firefox (Content-Type: text/plain)
              Erik Hansen Newbie

              Not sure why you would have to set that manually, if the page already has the contentType attribute set in the page directive.

              What I've noticed is that the JSPs that fail to render properly have only:

              <%@ page contentType="text/html;charset=UTF-8" language="java" %>

              in them with respect to content type and character encoding. The files that DO render correctly, have the same:

              <%@ page contentType="text/html;charset=UTF-8" language="java" %>

              as well as:

              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

              in the source of the page.

              In the case where the page has the <meta http=equiv tag, the response is received at mod_jk with the correct HTTP headers and the meta tag removed from the page (by JBoss/Tomcat?) and the page is rendered correctly.

              In the case where the page only has the JSP page directive for contentType, there is no HTTP header for Content-Type seen (by mod_jk) and is, apparently, tagged with the default Content-Type when a header is not found -- text/plain -- presumably by Apache on the way out.

              A) Why is the JSP directive not sufficient to generate the HTTP Content-Type header or who is dropping/ignoring/losing it?

              B) Isn't including the meta http-equiv tag in addition to setting the content type in the JSP redundant?