James-Jesse Drinkard
James-Jesse Drinkard

Reputation: 15723

Can't hit index.jsp in a Spring MVC application

I have a Spring 2.5.6 MVC application that I'm running on Tomcat 7. However, when I try to access the index.jsp page under http://localhost:8080/myapp-web/, I'm getting a 404 error. The context-root is /myapp-web/.

The servlet.xml:

...
<bean name="/app.htm" class="com.myapp.web.MyAppController">
        ...
  </bean>
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp"></property>        
  </bean>

The jsp file under WEB-INF is: index.jsp and is listed in the web.xml as:

<servlet-mapping>
    <servlet-name>myapp</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>
      index.jsp
    </welcome-file>
  </welcome-file-list>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>

  <servlet>
    <servlet-name>myapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

Everything appears to be correct here, but since I'm getting the 404, I realize I'm not finding the resource. Any ideas as to what I'm doing wrong here?

Aftermath:

There may be another issue with the original code, but I was able to get another tutorial working and I understand the mappings better from the answers I got.

Upvotes: 1

Views: 2853

Answers (1)

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 28045

You should either change <property name="prefix" value="/WEB-INF/jsp/" /> to <property name="prefix" value="/WEB-INF/" /> or move index.jsp to /WEB-INF/jsp/...

EDIT:

Try change servlet-mapping to:

<servlet-mapping>
  <servlet-name>myapp</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

Upvotes: 1

Related Questions