org.springframework.web.servlet.PageNotFound-未找到具有URI的HTTP请求的映射

org.springframework.web.servlet.PageNotFound-未找到具有URI的HTTP请求的映射,spring,hibernate,jsp,spring-mvc,Spring,Hibernate,Jsp,Spring Mvc,嗨,我是新春Mvc 我并不是不能解决这个问题 调度器servlet(servlet context.xml) 查看页面(home.jsp) 它抛出上述错误。您的两个方法被映射到/。但是您的URL是/customer 此外,这没有意义: <form action="customer" action="addCustomer"> 一个窗体只能有一个操作。如果要调用addCustomer方法,则应 <form action="<c:url value='/'/>"

嗨,我是新春Mvc

我并不是不能解决这个问题

调度器servlet(servlet context.xml)

查看页面(home.jsp)


它抛出上述错误。

您的两个方法被映射到
/
。但是您的URL是
/customer

此外,这没有意义:

<form action="customer" action="addCustomer">

一个窗体只能有一个操作。如果要调用addCustomer方法,则应

<form action="<c:url value='/'/>" method="post">

您还可以使用spring标记库来帮助生成URL

例如:

 <spring:url value="/model/customer" var="url" />
 <a href="${url}">Link</a>

您的组件扫描标签扫描“com.projects.model”包,但您的控制器在“com.myprojects.controller”包中更改组件扫描 从



然后试试看

package com.myprojects.controller;


import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.projects.model.CustomerDao;
import com.projects.model.Customer;


@Controller
public class HomeController {

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

/**
 * Simply selects the home view to render by returning its name.
 */

private CustomerDao dao;



@RequestMapping(value = "/", method = RequestMethod.GET)        
public String customer(Locale locale, Model model) {
    logger.info("Welcome home! The client locale is {}.", locale);

    return "home";
}

@RequestMapping(value = "/", method = RequestMethod.POST)
    public String addCustomer(@ModelAttribute("customer") Customer customer, BindingResult result) {

    dao.save(customer);

    return "home";
  }



}
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>


 <P>  The time on the server is ${serverTime}. </P> --%>

<form action="addCustomer">
Cust_Id :
<input type="text">
<br>
Name :
<input type="text">
<br>
Age :
<input type="text">

<input type="submit" value="Save">
</form>
</body>
</html>
 http://localhost:8080/model/customer
<form action="customer" action="addCustomer">
<form action="<c:url value='/'/>" method="post">
 <spring:url value="/model/customer" var="url" />
 <a href="${url}">Link</a>
<context:component-scan base-package="com.projects.model" />
<context:component-scan base-package="com.myprojects.controller"/>