无法强制Spring Web MVC 3.0框架正常工作

| 我正在用Java构建Web应用程序。试图集成Spring Web MVC 3.0框架。但是我什至不能简单地显示页面。我正在使用NetBeans 7.0和Tomcat 6.0。 这是我所拥有的: 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\"
    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\">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
    </welcome-file-list>
</web-app>
Dispatcher-servlet.xml:
<?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\">

    <context:component-scan base-package=\"forum.web\" />        

    <!--
    Most controllers will use the ControllerClassNameHandlerMapping above, but
    for the index controller we are using ParameterizableViewController, so we must
    define an explicit mapping for it.
    -->
    <bean id=\"urlMapping\" class=\"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping\">
        <property name=\"mappings\">
            <props>
                <prop key=\"index.htm\">indexController</prop>
            </props>
        </property>   
    </bean> 
    <!--  org.springframework.web.servlet.view.InternalResourceViewResolver -->
    <bean id=\"viewResolver\" class=\"org.springframework.web.servlet.view.UrlBasedViewResolver\">
        <property name=\"viewClass\" value=\"org.springframework.web.servlet.view.JstlView\" />
        <property name=\"prefix\" value=\"/WEB-INF/jsp/\" />
        <property name=\"suffix\" value=\".jsp\" />
    </bean>


    <!--
    The index controller.
    -->
    <bean name=\"indexController\"
          class=\"org.springframework.web.servlet.mvc.ParameterizableViewController\"
          p:viewName=\"index\" />


</beans>
控制器:
package forum.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 *
 * @author 
 */
@Controller
public class RegistrationController
{
    @RequestMapping(\"/registration.htm\")
    public ModelAndView registrationWindow() 
    {       
        return new ModelAndView(\"registration\");
    }
}
XHTML页面:
<tr id=\"log_reg\">
      <td>
          <a href=\"login.htm\"> Log in </a>
          </td>
      <td></td>
      <td>
        <a href=\"registration.htm\"> Register </a>
        </td>
   </tr>
运行此命令,我看到索引页面:
http://localhost:8088/Forum/index.htm   
在页面上,我单击链接,打开打开注册页面。但相反,我看到HTTP 404错误。 链接:
http://localhost:8088/Forum/registration.htm
在NetBeans上发现错误:
18-Jun-2011 14:45:19 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.htm] onto handler [org.springframework.web.servlet.mvc.ParameterizableViewController@1fb0fc2]
18-Jun-2011 14:45:20 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet \'dispatcher\': initialization completed in 1279 ms
18-Jun-2011 14:45:20 org.apache.catalina.core.StandardContext start
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Forum] has already been started
18-Jun-2011 14:45:35 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/Forum/registration.htm] in DispatcherServlet with name \'dispatcher\'
18-Jun-2011 14:51:53 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/Forum/registration.htm] in DispatcherServlet with name \'dispatcher\'
我无法消除造成这些错误的原因。我认为代码看起来不错。这次我尝试了很多事情。 有什么帮助吗? 最好的祝福     
已邀请:
        可能是因为同时使用了注释映射和SimpleUrlHandlerMapping。 尝试添加bean:
<bean id=\"handlerMapping\" class=\"org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping\">
</bean>
并将其作为处理程序添加到您的urlMapping bean中:
<property name=\"interceptors\">
   <list>
     <ref bean=\"handlerMapping\"/>
   </list>
</property>
仅使用其中之一比较容易,尤其是基于注释的控制器。在这种情况下,您必须扔掉urlMapping bean,而不是indexController bean,使用简单的类,例如:
@Controller
class PagesCtrl {
    @RequestMapping(\"/index.htm\")
    ModelAndView index() {
        ModelAndView mav = new ModelAndView(\"index\")
        return mav
    }
}
    

要回复问题请先登录注册