2016-05-19 13 views
0

maven、Spring 3.1.1を使用してモデルとコントローラで単純なログインページを作成しています。私はモデルとコントローラを作成しました。しかし、アプリケーションを実行している間、私は私のブラウザで404エラーを取得し、コンソールに、私は次のエラーを取得しています:私は適切な構成をチェックした名前 'dispatcher'を持つDispatcherServletのURI [/ TEST2 /]を持つHTTP要求のマッピングが見つかりません

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TEST2/] in DispatcherServlet with name 'dispatcher'

と私は、このために、正確なエラーを見つけることができませんでした。

私はいくつかの設定を変更しました。私は/*をURLマッピングに入れてみましたが、私は同じ問題に直面しています。

マイにおけるWeb.XML

<?xml version="1.0" encoding="ISO-8859-1" ?> 
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
     version="2.4"> 

     <display-name>Spring MVC Application</display-name> 

     <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>/</url-pattern> 
     </servlet-mapping> 

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

     <listener> 
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
     </listener> 
    </web-app> 

ディスパッチャ-servlet.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:context="http://www.springframework.org/schema/context" 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"> 

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


    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/pages/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 

</beans> 

LoginController.Java

package com.concretepage.controller; 

import javax.servlet.http.HttpServletRequest; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
public class LoginController { 

    @RequestMapping(value="/login", method = RequestMethod.GET) 
    public String login(){ 
     return "redirect:pages/login.jsp"; 
    } 

    @RequestMapping(value="pages/userCheck", method = RequestMethod.POST) 
    public String userCheck(ModelMap model, HttpServletRequest request) { 
     String name=request.getParameter("name"); 
     String pwd=request.getParameter("pwd"); 
     if("concretepage".equalsIgnoreCase(name)&&"concretepage".equalsIgnoreCase(pwd)){ 
      model.addAttribute("message", "Successfully logged in."); 

     }else{ 
      model.addAttribute("message", "Username or password is wrong."); 
     } 
     return "redirect:success.jsp"; 
    } 

} 

何私の間違い?

+0

http://stackoverflow.com/questions/16666988/spring-mvc-no-handler-found – shankarsh15

+0

リクエストURLとコンテキストパスは何ですか?注釈を有効にします。 – Blank

+0

アプリケーションにアクセスするために使用しているURLは何ですか? –

答えて

0

あなたはルートパスのマッピングを置いていない '/'

@RequestMapping(value="/", method = RequestMethod.GET) 
public String login(){ 
    return "redirect:pages/login.jsp"; 
} 

にこのコード

@RequestMapping(value="/login", method = RequestMethod.GET) 
public String login(){ 
    return "redirect:pages/login.jsp"; 
} 

を変更し、出力を確認し 。

関連する問題