Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Spring 在名为';调度员';_Spring_Spring Mvc - Fatal编程技术网

Spring 在名为';调度员';

Spring 在名为';调度员';,spring,spring-mvc,Spring,Spring Mvc,我收到一个警告:警告:在名为“dispatcher”的DispatcherServlet中找不到URI为[/Project/testAddUser]的HTTP请求的映射 我找不到哪里错了。我参考了许多教程,我认为我的项目配置正确。有人能帮忙吗?提前谢谢 这是我的web.xml文件 <context-param> <param-name>contextConfigLocation</param-name> <param-va

我收到一个警告:警告:在名为“dispatcher”的DispatcherServlet中找不到URI为[/Project/testAddUser]的HTTP请求的映射

我找不到哪里错了。我参考了许多教程,我认为我的项目配置正确。有人能帮忙吗?提前谢谢

这是我的web.xml文件

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml /WEB-INF/hibernateContext.xml</param-value>
    </context-param>
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>


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

上下文配置位置
/WEB-INF/applicationContext.xml/WEB-INF/hibernateContext.xml
调度员
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
1.
调度员
/
这是我的applicationContext.xml。 我尝试了
,但出现了其他错误。因此,我提出一个意见,以摆脱这一点

<context:annotation-config />
<!-- 
<context:component-scan base-package="com.plainart.member.controller" />
 -->
<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

我的控制器

package com.plainart.member.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.plainart.member.model.User;
import com.plainart.member.service.UserService;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String listUsers(Map<String,Object> map){
        map.put("user",new User());
        map.put("userList",userService.listUser());
        return "index";
    }

    @RequestMapping(value ="/")
    public String index(){
        return "index";
    }


    @RequestMapping("/testAddUser")
    public String testAddUser(){
        User testUser = new User();
        testUser.setFirstName("John");
        testUser.setLastName("Smith");
        userService.addUser(testUser);
        return "testUser";
    }

    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public String addUser(@ModelAttribute("user")User user,BindingResult result){
        userService.addUser(user);
        return "redirect:/index";
    }

    @RequestMapping("/deleteUser")
    public String deleteUser(@PathVariable("userId")Integer id){
        userService.removeUser(id);
        return "redirect:/index";
    }
}
包com.plainart.member.controller;
导入java.util.Map;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.validation.BindingResult;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入com.plainart.member.model.User;
导入com.plainart.member.service.UserService;
@控制器
公共类用户控制器{
@自动连线
私人用户服务;
@请求映射(“/index”)
公共字符串listUsers(映射){
put(“user”,newuser());
put(“userList”,userService.listUser());
返回“索引”;
}
@请求映射(value=“/”)
公共字符串索引(){
返回“索引”;
}
@请求映射(“/testAddUser”)
公共字符串testAddUser(){
用户testUser=新用户();
testUser.setFirstName(“John”);
testUser.setLastName(“史密斯”);
userService.addUser(testUser);
返回“testUser”;
}
@RequestMapping(value=“/addUser”,method=RequestMethod.POST)
公共字符串addUser(@modeldattribute(“user”)用户,BindingResult){
userService.addUser(用户);
返回“重定向:/index”;
}
@请求映射(“/deleteUser”)
公共字符串deleteUser(@PathVariable(“userId”)整数id){
userService.removeUser(id);
返回“重定向:/index”;
}
}

您需要创建dispatcher-servlet.xml文件,并将控制器包放在那里

<context:annotation-config />
<context:component-scan base-package="com.plainart.member.controller" />
<mvc:annotation-driven />

然后将其映射到web.xml文件中

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

上下文配置位置
/WEB-INF/dispatcher-servlet.xml
我认为您在初始化配置位置时遇到了问题。 用下面的方法试试看

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

上下文配置位置
/WEB-INF/applicationContext.xml、/WEB-INF/hibernateContext.xml、/WEB-INF/dispatcher-servlet.xml

您需要创建dispatcher-servlet.xml文件,并将控制器包放在那里

<context:annotation-config />
<context:component-scan base-package="com.plainart.member.controller" />
<mvc:annotation-driven />

然后将其映射到web.xml文件中

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

上下文配置位置
/WEB-INF/dispatcher-servlet.xml
我认为您在初始化配置位置时遇到了问题。 用下面的方法试试看

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

上下文配置位置
/WEB-INF/applicationContext.xml、/WEB-INF/hibernateContext.xml、/WEB-INF/dispatcher-servlet.xml

感谢您的跟进。我试过了,但现在出现了404错误。我的@RequestMapping有什么问题吗?谢谢你的跟进。我试过了,但现在出现了404错误。我的@RequestMapping有什么问题吗?