CrownCowcow 2019-09-02 17:53 采纳率: 0%
浏览 523

No mapping found for HTTP request with URI

No mapping found for HTTP request with URI

问题描述:运行一直有No mapping found for HTTP request with URI [/enterprisemana/login] in DispatcherServlet with name 'springDispatcherServlet'的问题。

项目的目录结构:

图片说明

其中web.xml的配置

 <servlet>
    <servlet-name>springDispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring*.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

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

  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

spring.xml的配置:

    <!-- 进行包扫描 -->
    <context:component-scan base-package="com.August."/>
</beans>

然后是spring-mvc.xml的配置

 <!-- 1.配置注解 -->
    <mvc:annotation-driven/>




    <!-- 2.配置扫描,扫描指定包中的控制器
    <context:component-scan base-package=""></context:component-scan>
     扫描器会扫描带有@Component@Service@Controller@Component等注解,并实现相应的操作 -->

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



    <!-- 3.配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- prefix代表前缀,suffix代表后缀 -->
        <property name="prefix" value="/WEB-INF/user/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>


    <!-- 放行如JS这样的静态资源 -->
    <mvc:default-servlet-handler/>

然后在登录界面的表单:

<form action="login" method="post">
        Account: <input type="text" name="account"/><br/><br/>
        Password:<input type="password" name="password"/><br/><br/>
        Character:<input type="radio" name="character" value="buyer" checked/>Buyer
                  <input type="radio" name="character" value="saler"/>Saler
                  <input type="radio" name="character" value="stockman"/>Stockman
                  <input type="radio" name="character" value="sysman"/>System Manager
                  <br/><br/>
        <input type="submit" value="Login"/>
    </form>

Controller:

package com.August.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.August.entity.User;
import com.August.service.UserService;

@Controller
//@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userservice;

    @RequestMapping("login")
    public String Login(String account,String password,String character,HttpSession session) {
    //删掉了业务操作,直接转发页面
        return "buyer";
    }
}

输出结果:

DEBUG [http-apr-8080-exec-5] - DispatcherServlet with name 'springDispatcherServlet' processing POST request for [/enterprisemana/login]
 **WARN [http-apr-8080-exec-5] - No mapping found for HTTP request with URI [/enterprisemana/login] in DispatcherServlet with name 'springDispatcherServlet'**
DEBUG [http-apr-8080-exec-5] - Successfully completed request

新手小白,找了好久的问题,找不出来。。求助

  • 写回答

1条回答 默认 最新

  • Json-Huang 2019-09-02 21:56
    关注

    UserController没有对应的/enterprisemana/login,把

    //@RequestMapping("/user")改成如下,记得把前面//去掉
    @RequestMapping("/enterprisemana")
    
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题