这是我用于 spring mvc 的当前配置:
1- web.xml:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/config/dispatcherServlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2- dispatcherServlet.xml:
<context:component-scan base-package="com.app" />
<context:annotation-config />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
3-控制器:我的网页直接在 webapp 文件夹下
@Controller
public class SearchController {
private Log log = LogFactory.getLog(getClass());
@RequestMapping("/search.jsp")
public String search(Model model, HttpServletRequest request,
HttpSession session) {
log.debug("Search Controller");
return "search";
}
ISSUE:尝试访问搜索页面时,如下所示:
http://localhost:8080/MyAPP/search.jsp
控制器没有被调用,但是当我将调度程序 servlet 映射到/mapping/*
并访问搜索页面时,如下所示:
http://localhost:8080/MyAPP/mapping/search.jsp
控制器被正确调用,我正在使用spring 3.0.5.RELEASE。
请指教,谢谢。