2017-01-17 5 views
0

私は春に新しく、コントローラで単純なディスパッチャサーブレットを設定しようとしていますが、動作させることができません。 http://localhost:8080/1/dispatcher/indexに行き、コンソールに「ようこそ」と表示したい。上司は、マッピングのためにindex.jspページに自動的にリダイレクトする必要があるとも言います。Spring - コントローラで単純なディスパッチャサーブレットを設定する

WelcomeController.java

@Controller 
public class WelcomeController { 

    @RequestMapping("/index") 
    public ModelAndView welcome() 
    { 
     System.out.println("welcome entered"); 


    } 
} 

web.xmlの

<web-app> 
    <display-name>Archetype Created Web Application</display-name> 
<!-- The front controller of this Spring Web application, responsible for handling all application requests --> 
    <servlet> 
     <servlet-name>springDispatcherServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 

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

    <!-- Map all requests to the DispatcherServlet for handling --> 
    <servlet-mapping> 
     <servlet-name>springDispatcherServlet</servlet-name> 
     <url-pattern>/dispatcher/</url-pattern> 
    </servlet-mapping> 
</web-app> 

springDispatcherServlet-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

    <context:component-scan base-package="com.paymon" /> 
<mvc:annotation-driven /> 

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

答えて

0

まずそれが指示されたコードがコンパイルされないようです。 welcome()メソッドは、表示するビューを示すModelView型のオブジェクトを返す必要があります。

このメソッドでは、ビューをリゾルバに置くことができます。show index.jspが必要な場合は、indexをviewNameメソッドに配置します。

関連する問題