2017-02-14 19 views
0

私はビューの名前をチェックした最後の文字列を返すpublic関数index()を持つ単一のコントローラクラス(MainController.class)を持つwarプロジェクトを持っています"index.jsp"という名前の単一のJSPに転送されました。ビューは/ main/webapp/WEB-INF/views/jsp /にあります。 MainController.java:Spring MVC要求されたリソースが利用できません

@Controller 
public class MainController 
{ 
    @Autowired 
    private ApplicationContextProvider mObjApplicationContextProvider; 

    @Autowired 
    private ScheduleService mObjScheduleService; 

    protected ApplicationContext getApplicationContext() 
    { 
     return(getApplicationContextProvider().getApplicationContext()); 
    } 

    protected ApplicationContextProvider getApplicationContextProvider() 
    { 
     return(mObjApplicationContextProvider); 
    } 

    protected Object getBean(final Class<?> clsBean) 
    { 
     return(getApplicationContext().getBean(clsBean)); 
    } 

    protected Object getBean(final String sBeanName) 
    { 
     return(getApplicationContext().getBean(sBeanName)); 
    } 

    protected ScheduleService getScheduleService() 
    { 
     return(mObjScheduleService); 
    } 

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

のindex.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     <title>Insert title here</title> 
    </head> 
    <body> 
     Hello World! 
    </body> 
</html> 

私の構成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.xsd 
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> 

    <context:component-scan base-package="net.draconia.church" /> 

    <bean class="net.draconia.ApplicationContextProvider" /> 

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> 
     <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql:sql9.freemysqlhosting.net/sql9158326" /> 
     <property name="username" value="sql9158326" /> 
     <property name="password" value="MqX7sbacgB" /> 
    </bean> 

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

    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <mvc:annotation-driven /> 

</beans> 

私は「http://localhost:8080/Ushering/に行きます":404 - "要求されたリソースは利用できません。 "

ログには何も見つかりませんが、必要な場合は投稿できますので、利用できないファイルやリソースを教えてください。 1つのログファイルにコントローラのRequest Mappingが記述されているため、コントローラを見つけることができるようです。どうなり得るか?

編集:WARファイルは、pomファイルで定義されているようにUsheringされています。また、プロジェクトの名前としてweb.xmlにも定義されていますので、コンテキストがUsheringであると思います。物事は/ Usheringの後になるので、もし私が/ Helloにrequestmappingを設定すると、URLはlocalhost:8080/Ushering/Helloになるはずです。

編集:私の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_3_0.xsd" version="3.0"> 
    <display-name>CrunchifySpringMVCTutorial</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

    <servlet> 
     <servlet-name>Ushering</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/Ushering-config.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Ushering</servlet-name> 
     <url-pattern>/s</url-pattern> 
    </servlet-mapping> 
</web-app> 
+0

web.xmlファイルを投稿できますか? – dennislloydjr

+0

編集として追加しました –

+0

私はそれを得ました! web.xml -/sをurlパターンの下に配置したときに私が気づいたタイプミスがありました。 /と/でなければなりません。私は "s"を取り除き、コンパイル戦争を戦争:それを戦争し、私が期待しているようになった: - D私は正しい方向に私を突き刺してくれてありがとう! –

答えて

0

あなたがメインコントローラクラスを見てみると、「インデックス」を返すメソッドを扱う唯一の要求があります。 "/"にマップされているため、localhost:8080と入力すると、それに応じてインデックスファイルが返されます。したがって、入力する代わりにlocalhost:8080/Usheringlocalhost:8080を入力します。それはうまくいくだろう。しかし、localhost:8080/Usheringと入力する場合は、コントローラファイル内の要求マッピングを次のように変更します。

@RequestMapping(値= "/先導")

public String index() 
{ 
    return("index"); 
} 

それはあなたのインデックスファイルを返します。

+0

どうすればいいのかわかりません - 戦争はUshering.warで、warappファイルをwebappsにコピーすると、TomcatのWebAppsフォルダの下にフォルダを作成してコンテキストを作成します。私がhttp:// localhost:8080と入力すると、「これが見えたら、正式にTomcatをインストールしました!おめでとうございます!ページ。 –

関連する問題