我对 spring mvc web 应用程序进行了非常基本的设置。下面是我的 web.xml 映射:
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
和 spring-config.xml
<mvc:default-servlet-handler/>
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:component-scan base-package="cz.dmostek"/>
<context:annotation-config/>
这是我的jsp页面目录结构
`-- web
`-- WEB-INF
|-- pages
| |-- css
| | |-- foundation.css
| | `-- normalize.css
| |-- images
| |-- index.jsp
| `-- js
`-- web.xml
我的控制器声明如下:
@Controller
public class TestController {
@RequestMapping(value = "/")
public String
return "index";
}
}
但是,当我尝试访问 localhost:8080/app/ 时,出现 404 错误。在日志中我有 2013-10-1916:12:09,326 () DEBUG DispatcherServlet - Successfully completed request
如果我调试应用程序一切正常,控制器被调用,视图被渲染,但我仍然得到 404。你怎么看?