Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
请求映射不工作。SpringMVCMaven_Maven_Spring Mvc - Fatal编程技术网

请求映射不工作。SpringMVCMaven

请求映射不工作。SpringMVCMaven,maven,spring-mvc,Maven,Spring Mvc,我的请求映射在SpringMVC中不起作用。加载第一页index.jsp。 当它重定向到某个操作时,控制器不会被调用。 以下是我的作品: 这是我的web.xml: <web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <par

我的请求映射在SpringMVC中不起作用。加载第一页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>

Web应用程序创建的原型
上下文配置位置
/WEB-INF/dispatcher-servlet.xml
org.springframework.web.context.ContextLoaderListener
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
这是我的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>

/WEB-INF/views/
.jsp
这是我的控制器类:

            @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>
@RequestMapping(value=“/dashboard”,method=RequestMethod.POST)
公共ModelAndView仪表板(@RequestParam(value=“name”,required=false)字符串名称){
ModelAndView视图=新的ModelAndView(“仪表板”);
view.addObject(“name”,name);
返回视图;
下面是Index.jsp
登录
注册
用户名

这是根据spring mvc的基本教程编写的。请告诉我哪里出了问题。提前感谢。

您应该在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>

springMVC
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
类路径:spring/ApplicationContext-mvc.xml
1.

dispatcher org.springframework.web.servlet.Dispatchers servlet contextConfigLocation/web-INF/dispatcher-servlet.xml 1它被定义为上下文参数,但我定义为init参数和您应该使用绝对路径,或者使用相对于类路径的路径(当您的项目运行时,它将是projectPath/WEB-INF/classes),我认为第二种方法更好默认的spring mvc dispatcher路径是WEB-INF目录,名称是[]-servlet.xml,所以配置也应该可用,但我不知道为什么它对您没有用处