我正在使用来自openshift的预设置Maven项目,当我在Tomcat上运行应用程序时,答案是“HTTP状态404 - /WEB-INF/views/hello.jsp” 这是web.xml
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
调度员的servlet
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
的hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<h1>Message : ${message}</h1>
</body>
</html>
和控制器
@Controller
@RequestMapping("/welcome")
public class Test {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring 3 MVC - Hello World");
return "hello";
}
}
我的IDEA Spring服务显示它无法在“return”中解析“hello”hello“;” 当我要求http://localhost:9999/welcome时,日志中没有错误只显示“HTTP状态404 - /WEB-INF/views/hello.jsp”; 感谢大家的回答
如果有人感兴趣的话,这里的PS是源代码,谢谢答案 0 :(得分:2)
在视图解析器中,您指向/ WEB-INF / views而不是使用 值= “/ WEB-INF /页/” 然后hello.jsp应该出现。