所以,我有一个转到index.jsp的主页。哪个好。在这个页面上有一个搜索按钮,它应该会带你进入room-list.jsp,但它只是嵌入到index.jsp中,我无法理解为什么。
我已尝试返回"重定向:/ room-list"但这似乎是试图去另一个控制器而不是一个jsp,如果这是有道理的?我很困惑。这里有一个截然不同的截图,因为你可以看到自从list.jsp添加到index.jsp之后的第2个横幅:http://imgur.com/fJ3BA67
这是我控制器中的内容:
@RequestMapping("/home")
public String home() {
System.out.println("in controller");
return "index";
}
@RequestMapping(value = "/search", method = RequestMethod.POST)
public String showMessage2(@Valid SearchCmd searchCmd, Model model) {
System.out.println("in search controller");
return "room-list";
}
Web.xml中 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" ID =" WebApp_ID"版本=" 3.0">
<display-name>Archetype Created Web Application</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>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
调度-servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.programcreek" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
答案 0 :(得分:0)
因为您正在使用:
RequestMethod.POST
尝试将其更改为:
RequestMethod.GET
您将重定向到房间列表页面。
本教程可能有所帮助:http://krams915.blogspot.com/2011/01/spring-mvc-3-hibernate-annotations.html
他正在使用
@RequestMapping(value = "/persons/edit", method = RequestMethod.GET)
要先获取页面,然后使用
@RequestMapping(value = "/persons/edit", method = RequestMethod.POST)
做生意。