0
votes

i have a simple spring application and there are many post about this issue but i am not able to see where i wrong. I am not able to view displayAllOrders.jsp as mapping not found is displayed. :(

Please find below my web.xml mapping:

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

Please find below 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" />

Please find below my controller(package: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;
}

Please find below the href tag in the page home.jsp(Path:src\main\webapp\WEB-INF\views\home.jsp) page that calls displayAllOrders.jsp(Path:src\main\webapp\WEB-INF\views\displayAllOrders.jsp):

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

I am able to display the home page, but when i click on the hyperlink displayAllOrders:

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

Any ideas why my mapping is not working for displayAllOrders please?

Thanks in advance.

1
try adding controller specific request mapping and change anchor tag href attribute with ${contextPath}/your-mapping for method. - Dangling Piyush

1 Answers

0
votes

Your url mapping is for /displayAllOrders not for /project/displayAllOrders, please change the RequestMapping in the controller and try.