2016-05-07 8 views
1

私は日食で、次の春のプロジェクトがあります。Spring MVC Webアプリケーションの開始ページを設定しますか?

enter image description here

私がに行くとき:

http://[my-host]:8082/webapp-module/hello 

WEB/INF/JSP/Hello.jspのページがうまくロードされています。

http://[my-host]:8082/webapp-module 

動作しません。現在:しかし、私はまた私がに行くときに、デフォルトのスタートページ(WEB/INF/index.jspの)を定義したいと思います。このために別のコントローラを追加する必要がありますか?

マイのweb.xmlファイル

<web-app id="WebApp_ID" version="2.4" 
    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"> 

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

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

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

    <servlet> 
     <servlet-name>webapp-module</servlet-name> 
     <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>webapp-module</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

そして、私のWebアプリケーション・モジュール-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" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

<context:annotation-config/> 

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

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

</beans> 

答えて

1

ステップ1:/WEB-INF/jsp/フォルダ内のindex.jspを移動します。

ステップ2:

@RequestMapping("/") 
public String home(){ 
    return "index"; 
} 

あなたの完全なコントローラクラスは次のようになります:あなたの@Controllerクラスでは、メソッドの下に追加

@Controller 
public class LoginController { 

    @RequestMapping("/") 
    public String home(){ 
     return "index"; 
    } 

    @RequestMapping("/hello") 
    public String showhello(){ 
     return "hello"; 
    } 
} 
関連する問題