0

我有一个简单的弹簧应用程序,有很多关于这个问题的帖子,但我看不到我错在哪里。由于显示未找到映射,我无法查看 displayAllOrders.jsp。:(

请在下面找到我的 web.xml 映射:

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/pres.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet> 

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

请在 pres.xml 下方找到:

<!-- DispatcherServlet Context: defines this servlet's request-processing 
    infrastructure -->
<context:component-scan base-package="com.example.pres" />
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory -->
<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<beans:bean id="validator"
        class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

请在我的控制器下方找到(包:com.example.pres):

@Controller
public class OrderController {

private static final Logger logger = LoggerFactory
        .getLogger(OrderController.class);

@Autowired
OrderService orderService;

@RequestMapping(method=RequestMethod.GET,value="/displayAllOrders")
public ModelAndView listPeople() {
    logger.debug("Received request to list orders");
    ModelAndView mav = new ModelAndView();
    List<Order> order = orderService.getAllOrders();
    logger.debug("Order Listing count = "+order.size());
    mav.addObject("order",order);
    mav.setViewName("displayAllOrders");
    return mav;
}

请在调用 displayAllOrders.jsp(Path:src\main\webapp\WEB-INF\视图\displayAllOrders.jsp):

<a href=displayAllOrders> View order</a>

我能够显示主页,但是当我单击超链接 displayAllOrders 时:

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/project/displayAllOrders] in DispatcherServlet with name 'appServlet'

任何想法为什么我的映射不适用于 displayAllOrders?

提前致谢。

4

1 回答 1

0

您的 url 映射/displayAllOrders不适用于/project/displayAllOrders,请RequestMapping在控制器中更改并尝试。

于 2013-01-26T07:00:12.590 回答