我有一個非常簡單的問題。當我在我的.jsp文件中有一個** /註冊的鏈接,方法viewRegistration被執行,一切工作正常。如果我有一個鏈接到**/registration/getTags?tagName = blahblah page is not found。我不知道爲什麼,因爲我認爲我的requestMapping註釋看起來是正確的......我將非常感謝您的幫助!請求映射 - Spring 4 - 不起作用
控制器:
@Controller
@RequestMapping(value = "/registration")
public class HelloController {
final static Logger logger = Logger.getLogger(HelloController.class);
@RequestMapping(method = RequestMethod.GET)
public String viewRegistration(Map<String, Object> model, HttpSession session) {
...
}
@RequestMapping(value = "/getTags", method = RequestMethod.GET)
public @ResponseBody
List<Tag> getTags(@RequestParam String tagName) {
....
}
}
WEB.XML:
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>aa</display-name>
<servlet>
<servlet-name>xxx</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>xxx</servlet-name>
<url-pattern>/registration/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/xxx-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
XXX-servlet.xml中:
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="movies.controller" />
<context:property-placeholder location="/WEB-INF/properties/website.properties" />
<context:component-scan base-package="com" />
<context:annotation-config />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"
id="tilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tile/tilesJsp.xml</value>
</list>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"
id="viewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="website" />
</bean>
</beans>
編輯編輯編輯: 我甚至嘗試某事更加簡單:
@RequestMapping(value = "/getTags")
@ResponseBody
public List<Tag> getTags() {
String tagName="";
return simulateSearchResult(tagName);
}
但仍然/ registration/getTags不起作用...,頁面未找到。
這是正確的方式,只要我還記得。 – kazbeel
不幸的是它不起作用,仍然沒有找到頁面 – user2455862