我正在尝试制作示例 Spring 3 Web Hello World 示例,但 InternalResourceViewResolver 未显示我的 jsp 页面?
web.xml
[CODE]<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>testbox</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>[/CODE]
dispatcher-servlet.xml
[CODE]<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>[/CODE]
有人可以告诉我发生了什么事或如何调试它
最佳答案
请发布您的 Controller 代码,您的jsp是否位于/WEB-INF/views?
确保您的 jsp 文件名与 Controller 方法中的返回字符串相同。
如果您有多个静态 jsp 并使用 <mvc:view-controller>
定义它们不太漂亮,你可以定义一个类似这样的 Controller
@Controller
public class MyController {
@RequestMapping("/view/{name}")
public String myView(@PathVariable("name") String name) {
return name;
}
}
现在可以通过 url“/view/”访问您的 jsp
关于java - Spring 3 - InternalResourceViewResolver 不显示我的 jsp 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5606279/