0

我之前已经设置了一些 Spring MVC 配置,但这次我似乎遗漏了一些东西。配置如下:

网页.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/dispatcher-servlet.xml
    </param-value>
</context-param>    

<listener>
    <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>

<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>/test/*</url-pattern>
</servlet-mapping>

调度程序-servlet.xml:

<context:annotation-config />

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

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/gupld">uploadController</prop>
        </props>
    </property>
</bean>

<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>

人控制器.java:

package mypackage.controller;

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

@Controller
public class MainController {

    @RequestMapping("/test")
    public ModelAndView welcome() {
        ModelAndView mav = new ModelAndView("_index");
        return mav;
    }
}

当我打电话时,http://127.0.0.1:8080/mycontext/test/我得到:

http-8080-1 INFO  2012-12-26 09:27:24,799 SimpleUrlHandlerMapping - Mapped URL path [/test] onto handler 'mainController'
http-8080-1 WARN  2012-12-26 09:27:24,887 PageNotFound - No mapping found for HTTP request with URI [/mycontext/test/] in DispatcherServlet with name 'dispatcher'

任何想法?

4

1 回答 1

0

您正在使用 url-pattern/test/*来加载dispatcherservlet。

但是您发送/mycontext/test/的不是映射到提供的网址。

尝试使用这个,

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*/test</url-pattern>
</servlet-mapping>

或使用此

<servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
于 2012-12-26T09:24:48.543 回答