2017-09-06 13 views
2

私のリクエストマッピングは、春のMVCでは動作しません。最初のページのindex.jspがロードされます。 アクションにリダイレクトされると、コントローラは呼び出されません。ここ は私の成果物です。ここリクエストマッピングが機能しません。 springmvc maven

は私のweb.xmlです:ここでは

 <web-app> 
      <display-name>Archetype Created Web Application</display-name> 
      <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> 

      <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> 
     </web-app> 

は私のディスパッチャ-servlet.xmlです:ここで

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

      <bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
       <property name="prefix"> 
        <value>/WEB-INF/views/</value> 
       </property> 
       <property name="suffix"> 
        <value>.jsp</value> 
       </property> 
      </bean> 
      <mvc:annotation-driven /> 
      <mvc:resources mapping="/resources/**" location="/resources/" /> 

     </beans> 

は私のコントローラクラスである:

  @RequestMapping(value ="/dashboard", method = RequestMethod.POST) 
      public ModelAndView dashboard(@RequestParam(value = "name", required = false) String name) { 

       ModelAndView view = new ModelAndView("dashboard"); 
       view.addObject("name", name); 
       return view; 
    Below is the Index.jsp 

     <form:form class="form-horizontal" method="POST" action="dashboard"> 
       <div class="login-wrap"> 
       <div class="login-html"> 
        <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Sign In</label> 
        <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label> 
        <div class="login-form"> 
         <div class="sign-in-htm"> 
          <div class="group"> 
           <label for="user" class="label">Username</label> 
           <input id="user" type="text" class="input"> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
      </form:form> 

     </body> 
     </html> 

これはspring mvcの基本チュートリアルと同じです。物事がうまくいかない場所を教えてください。前もって感謝します。

答えて

0

spring mvcサーブレットタグでinitパラメータを設定する必要があります。また、ディスパッチャサーブレットに設定を見つける場所を伝えることができます。

<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:spring/ApplicationContext-mvc.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
+0

\t \tののディスパッチャ \t \tのの \t \t \t org.springframework.web.servlet.DispatcherServlet \t \t \t \t ​​contextConfigLocation /WEB-INF/dispatcher-servlet.xml \t \tの 1 \tそれはコンテキストとして定義PARAMとにかくiは定義されましたinit paramとして試してみましたが、まだ同じ問題が発生しています。 –

+0

絶対パスを使用するか、クラスパスに相対パスを使用する必要があります(プロジェクトが実行されるときは** projectPath/WEB-INF/classes **になります)、第2の方法はより良いと思います –

+0

デフォルトのspring- mvcディスパッチャのパスはWEB-INFディレクトリですが、名前は[] - servlet.xmlなので、設定も利用できるはずですが、なぜそれがあなたにとって役に立たないのか分かりません –

関連する問題