请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

No mapping found for * with URI [/user/login.do] in *with * 'dispatcher'

不论是自己敲的代码,还是自己桥的代码,都出现了这个问题,但是首页Hello World是正常显示的,当我想在浏览器测试接口请求的时候就出现报错了,不知道哪里没配好,折腾挺久的了,求教!四月 02, 2018 11:28:57 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound

警告: No mapping found for HTTP request with URI [/user/login.do] in DispatcherServlet with name 'dispatcher'

dispatcher-servelet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc.xsd">

   <context:component-scan base-package="com.mmall" annotation-config="true"/>

   <mvc:annotation-driven>
       <mvc:message-converters>
           <bean class="org.springframework.http.converter.StringHttpMessageConverter">
               <property name="supportedMediaTypes">
                   <list>
                       <value>text/plain;charset=UTF-8</value>
                       <value>text/html;charset=UTF-8</value>
                   </list>
               </property>
           </bean>
           <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
               <property name="supportedMediaTypes">
                   <list>
                       <value>application/json;charset=UTF-8</value>
                   </list>
               </property>
           </bean>
       </mvc:message-converters>
   </mvc:annotation-driven>



   <!-- 文件上传 -->
   <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
       <property name="maxUploadSize" value="10485760"/> <!-- 10m -->
       <property name="maxInMemorySize" value="4096" />
       <property name="defaultEncoding" value="UTF-8"></property>
   </bean>


</beans>

userController.java

package com.mmall.controller.portal;

import com.mmall.common.Const;
import com.mmall.common.ResponseCode;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IUserService;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
* Created by geely
*/
@Controller
@RequestMapping("/user/")
public class UserController {


   @Autowired
   private IUserService iUserService;


   /**
    * 用户登录
    * @param username
    * @param password
    * @param session
    * @return
    */
   @RequestMapping(value = "login.do")
   @ResponseBody
   public ServerResponse<User> login(String username, String password, HttpSession session){
       ServerResponse<User> response = iUserService.login(username,password);

       if(response.isSuccess()){
           session.setAttribute(Const.CURRENT_USER,response.getData());
       }
       return response;
   }

   @RequestMapping(value = "logout.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> logout(HttpSession session){
       session.removeAttribute(Const.CURRENT_USER);
       return ServerResponse.createBySuccess();
   }

   @RequestMapping(value = "register.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> register(User user){
       return iUserService.register(user);
   }


   @RequestMapping(value = "check_valid.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> checkValid(String str,String type){
       return iUserService.checkValid(str,type);
   }


   @RequestMapping(value = "get_user_info.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<User> getUserInfo(HttpSession session){
       User user = (User) session.getAttribute(Const.CURRENT_USER);
       if(user != null){
           return ServerResponse.createBySuccess(user);
       }
       return ServerResponse.createByErrorMessage("用户未登录,无法获取当前用户的信息");
   }


   @RequestMapping(value = "forget_get_question.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> forgetGetQuestion(String username){
       return iUserService.selectQuestion(username);
   }


   @RequestMapping(value = "forget_check_answer.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> forgetCheckAnswer(String username,String question,String answer){
       return iUserService.checkAnswer(username,question,answer);
   }


   @RequestMapping(value = "forget_reset_password.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> forgetRestPassword(String username,String passwordNew,String forgetToken){
       return iUserService.forgetResetPassword(username,passwordNew,forgetToken);
   }



   @RequestMapping(value = "reset_password.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<String> resetPassword(HttpSession session,String passwordOld,String passwordNew){
       User user = (User)session.getAttribute(Const.CURRENT_USER);
       if(user == null){
           return ServerResponse.createByErrorMessage("用户未登录");
       }
       return iUserService.resetPassword(passwordOld,passwordNew,user);
   }


   @RequestMapping(value = "update_information.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<User> update_information(HttpSession session,User user){
       User currentUser = (User)session.getAttribute(Const.CURRENT_USER);
       if(currentUser == null){
           return ServerResponse.createByErrorMessage("用户未登录");
       }
       user.setId(currentUser.getId());
       user.setUsername(currentUser.getUsername());
       ServerResponse<User> response = iUserService.updateInformation(user);
       if(response.isSuccess()){
           response.getData().setUsername(currentUser.getUsername());
           session.setAttribute(Const.CURRENT_USER,response.getData());
       }
       return response;
   }

   @RequestMapping(value = "get_information.do",method = RequestMethod.POST)
   @ResponseBody
   public ServerResponse<User> get_information(HttpSession session){
       User currentUser = (User)session.getAttribute(Const.CURRENT_USER);
       if(currentUser == null){
           return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"未登录,需要强制登录status=10");
       }
       return iUserService.getInformation(currentUser.getId());
   }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">

   <display-name>Archetype Created Web Application</display-name>
   <filter>
       <filter-name>characterEncodingFilter</filter-name>
       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
       <init-param>
           <param-name>encoding</param-name>
           <param-value>UTF-8</param-value>
       </init-param>
       <init-param>
           <param-name>forceEncoding</param-name>
           <param-value>true</param-value>
       </init-param>
   </filter>
   <filter-mapping>
       <filter-name>characterEncodingFilter</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>

   <listener>
       <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
   </listener>
   <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
           classpath:applicationContext.xml
       </param-value>
   </context-param>
   <servlet>
       <servlet-name>dispatcher</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>dispatcher</servlet-name>
       <url-pattern>*.do</url-pattern>
   </servlet-mapping>
</web-app>


请求链接为 localhost:8080/user/login.do


target中对应的几个filter,dispatcher也为红色,但是下面明明存在filter-mapping 就是不知道哪里出问题了

正在回答 回答被采纳积分+3

3回答

Geely 2018-04-05 15:25:28

你好亲爱的同学,目前看属于404的一个错误,检查一下tomcat webapp ROOT下是否发布过去,加载系统的日志也要发一下,看看为什么没有加载到这个urlpattern到系统里。

首页的helloworld有截图么,是不是咱们项目的index.jsp ?

还有你说的红色,有没有具体配置的截图发一下,包括idea给的提示。目前来看应该是idea的项目环境问题导致的。

1 回复 有任何疑惑可以回复我~
polo哦 2018-04-04 12:57:06

改成这个试试,注意mvc的路径改一改

    <servlet>

        <servlet-name>SpringMVC</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>classpath:applicationContext-mvc.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

        <!-- 启用异步支持 -->

        <async-supported>true</async-supported>

    </servlet>

    <servlet-mapping>

        <servlet-name>SpringMVC</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>


1 回复 有任何疑惑可以回复我~
提问者 慕粉4317610 2018-04-06 22:23:48

谢谢老师和菠萝?同学,重新搞了一下,发现这个问题不存在了,我也是郁闷了,而且还顺带出现了很多坑,当然都解决了!!!

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号