请求图不起作用。 springmvc maven

时间:2017-09-06 01:18:42

标签: maven spring-mvc

我的请求映射在spring MVC中不起作用。第一页index.jsp加载。 当它重定向到一个动作时,控制器不会被调用。 这是我的文物:

这是我的web.xml:

        <web-app>
            <display-name>Archetype Created Web Application</display-name>
            <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>
                <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>
        </web-app>

这是我的dispatcher-servlet.xml:

            <context:component-scan base-package="com.ta.controller" />

            <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>
            <mvc:annotation-driven /> 
            <mvc:resources  mapping="/resources/**" location="/resources/" />

        </beans>

这是我的Controller类:

            @RequestMapping(value ="/dashboard", method = RequestMethod.POST )
            public ModelAndView dashboard(@RequestParam(value = "name", required = false) String name) {

                ModelAndView view = new ModelAndView("dashboard");
                view.addObject("name", name);
                return view;
   Below is the Index.jsp

        <form:form class="form-horizontal"  method="POST" action="dashboard">
              <div class="login-wrap">
                <div class="login-html">
                    <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Sign In</label>
                    <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label>
                    <div class="login-form">
                        <div class="sign-in-htm">
                            <div class="group">
                                <label for="user" class="label">Username</label>
                                <input id="user" type="text" class="input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
          </form:form>

        </body>
        </html>

这是按照spring mvc的基本教程。请告诉我哪里出了问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

你应该在你的spring mvc servlet标签中设置init参数。他们可以告诉你dispatcherServlet在哪里找到你的配置。

<servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/ApplicationContext-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>