Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC gives 404 for simple JSP request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC gives 404 for simple JSP request

    All I want to do is display a JSP. Why does everything in Spring have to be a chore?!
    Here is my app-servlet.xml config:

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans     
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-4.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    
    
        <!-- Enable @Controller annotation support -->
        <mvc:annotation-driven />
    
        <!-- Allow static resources to be served from the /resources folder -->
        <mvc:resources mapping="/r/**" location="/resources/" />
    
        <!-- Scan classpath for annotations (eg: @Service, @Repository etc) -->
        <context:component-scan base-package="com.cs" />
    
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix">
                <value>/r/jsp/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>
    
        <context:property-placeholder location="file:/TcatServer6/myapp/properties/myapp/myapp.properties" />
    </beans>
    You can see all my resources are in /resources under my /src/main/webapp dir for maven/eclipse. I mapped them to /r/...

    Removing the InternalViewResolver made no difference.
    Here's my web.xml

    Code:
    <web-app 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"
              version="2.5">
      <display-name>myapp</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
      </welcome-file-list>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-security.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <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>
      <filter>
        <filter-name>httpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>httpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/welcome.html</url-pattern>
      </servlet-mapping>
      <servlet>
        <servlet-name>agent-desktop</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>myapp</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>
    I go to
    Code:
    http://localhost:8080/myapp/r/jsp/test.jsp
    and get a 404 It is there. I can go to every content type such as html, js, css. Each has a folder under /resources. JSP is the only one that doesn't work. When I change the to '/*' for the myapp servlet mapping THEN it finds the JSP but doesn't precompile it! It just serves it up as like a text file.

    Also with spring, it seems to just ignore my index.html welcome page. Spring MVC, so far, has taken about 10x as long to do anything I could do in 5 minutes in J2EE.
    Please help me not hate spring MVC.

  • #2
    In your ViewResolver configuration, you set up JSP views to be prefixed with "/r/jsp" and suffixed with ".jsp".
    That's the part described here in the reference documentation (mapping view names to actual JSPs).

    The second part missing in your question is: what does your controller looks like? How did you map URLs to Controllers?
    This is described here in the reference documentation.

    Anyway this question is probably a better candidate for StackOverflow, perhaps with the "spring-mvc" and "jsp" tags.
    Could you post your question there?

    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment


    • #3
      No one there seems to know either. I am inches from abandoning Spring. It has been nothing but headaches. If I can't compile a simple JSP then what good is it. I've heard more people complain about these kinds of issues in Spring and returning to a simpler J2EE type approach to things.

      Comment

      Working...
      X