我試圖使用我的web應用註釋控制器春3 MVC支持。 我的配置如下:@Controller沒有被調用的GET請求
1- web.xml中:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/springmvc/*</url-pattern>
</servlet-mapping>
2- applicationContext.xml中:我的網頁是web應用文件夾直接
<context:component-scan base-package="com.myapp" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
3下 - 控制器:
@Controller
@RequestMapping("/test.jsp")
public class Test{
@RequestMapping(method = RequestMethod.GET)
public String get() {
System.out.println("######## GET METHOD FOR test.jsp ########");
return "test.jsp";
}
}
注:我加載的applicationContext在的ServletContextListener如下:
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:spring/config/applicationContext.xml");
請告知如何解決這個問題,謝謝。
我也有一個問題,如果有可能,使調度員的servlet分派具體jsp頁面並不是所有的頁面中的應用,因爲不是所有的我的jsp頁面中有控制器。
跟着你的筆記,並且仍然有同樣的問題,是否可以與我加載的applicationContext的方式(請大家看看編輯問題)?也可以這與get方法的返回字符串有關嗎?請指教。 –
您需要通過查看日誌來檢查彈簧配置是否已加載。也正如@ tesla1984所提到的,將返回字符串更改爲「test」而不是「test.jsp」 –