Announcement Announcement Module
Collapse
No announcement yet.
JSP served out as plain/text with source code Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSP served out as plain/text with source code

    I have a JSP:

    Code:
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <html>
        <head>
            <title>wtf</title>
        </head>
        <body>
            <h2>Hello World!</h2>
            <c:set var="membersUrl">
                <c:url value="members" />
            </c:set>
            <a href="${membersUrl}">Members</a>
        </body>
    </html>
    If I remove the DispatcherServlet (and, thus, the view resolver), it renders correctly. However, if I use the view resolver, I get:

    Code:
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <html>
        <head>
            <title>wtf</title>
        </head>
        <body>
            <h2>Hello World!</h2>
            <c:set var="membersUrl">
                <c:url value="members" />
            </c:set>
            <a href="${membersUrl}">Members</a>
        </body>
    </html>
    The content type is set to plain/text and, even more oddly, the title of the page is "wtf" (indicating that the browser somehow read the title of the page).

    For reference, here's my serlvet configuration:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
        xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc">
    
        <context:component-scan base-package="com.googlecode.ticktokk.mvc" />
        <mvc:annotation-driven />
        <mvc:default-servlet-handler />
        <mvc:view-controller path="/login" view-name="login/index" />
        
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>
    ...and here's my web.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <display-name>TickTokk</display-name>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/applicationContext-*.xml</param-value>
        </context-param>
    
        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <servlet>
            <servlet-name>ticktokk</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>ticktokk</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    </web-app>

  • #2
    Hello

    Wich Spring Version you are using?
    Same question about the web container (Tomcat?, jetty?)

    Try cleaning and re building your application

    Comment


    • #3
      I'm using Spring 3.0.5.RELEASE (with Spring Security of the same version, if that's in any way relevant). I'm using Tomcat 6.0.26 through Eclipse WTP and jetty-maven-plugin 8.0.0.M2. Many Project > Clean and mvn clean invocations tried, to no avail. Interestingly, the output is a little different on Jetty:

      Code:
      <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
      Hello World!
      
      Members
      ("Members" is a link to "/${membersUrl}", and the "Hello World!" is properly rendered in <h2 /> tags)

      [ Edit: it's worth noting that, if I remove the taglib declaration (and the corresponding <c:* /> elements), it renders correctly. ]
      Last edited by jrh3k5; May 22nd, 2011, 07:44 PM.

      Comment


      • #4
        I'm having a similar issue. Anyone figure this one out?

        Comment


        • #5
          I'm using spring 3 and hibernate 4 and I found my issue with the jsp code and html code displaying raw in tomcat 7. In my web.xml I set the servlet as:
          <servlet>
          <servlet-name>appServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
          <load-on-startup>1</load-on-startup>
          </servlet>

          <servlet-mapping>
          <servlet-name>appServlet</servlet-name>
          <url-pattern>/*</url-pattern>
          </servlet-mapping>
          I took the * off so it was just

          <servlet>
          <servlet-name>appServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
          <load-on-startup>1</load-on-startup>
          </servlet>

          <servlet-mapping>
          <servlet-name>appServlet</servlet-name>
          <url-pattern>/</url-pattern>
          </servlet-mapping>
          and that fixed my issue. My models even display properly now. Ahhhh so nice.

          Comment

          Working...
          X