为什么Spring MVC应用程序不显示? [英] Why won't Spring MVC app display?
本文介绍了为什么Spring MVC应用程序不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的应用程序项目结构:
Here is my app project structure:
myapp/
src/main/java/
com.me.myapp.controllers.HelloController
src/main/config/
mvc-dispatcher-servlet.xml
web.xml
pages/
Hello.jsp
lib/
<JARs>
build.xml
我的mvc-dispatcher-servlet.xml
:
<?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-2.5.xsd">
<bean name="/hello.htm"
class="com.me.myapp.controllers.HelloController" />
<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>
</beans>
我的web.xml
:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Partner Demo</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
这是打包的WAR的结构(在我将其与Ant捆绑在一起之后):
Here is the structure of the packaged WAR (after I bundle it up with Ant):
myapp.war
META-INF/
WEB-INF/
classes/
lib/
pages/
Hello.jsp
mvc-dispatcher-servlet.xml
web.xml
将其部署到Tomcat并转到http://localhost:8080/myapp/hello.htm
时,我从Tomcat收到404 Not Found错误.
When I deploy this to Tomcat and go to http://localhost:8080/myapp/hello.htm
I get a 404 Not Found error from Tomcat.
编辑 :(显然)目标是转到该URL并查看我的Hello.jsp
页面.
Edit: The objective is (obviously) to go to that URL and see my Hello.jsp
page.
我要去哪里错了?
更新:我的HelloController
:
public class HelloController extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("Hello");
model.addObject("msg", "This should be visible.");
return model;
}
}
推荐答案
在web.xml文件中,您需要将*更改为* .htm
In web.xml file you need to change * into *.htm
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Partner Demo</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
这篇关于为什么Spring MVC应用程序不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文