2017-05-17 9 views
0

単純な「Hello World」アプリケーションを使用してJava EEを学習しています。index.htmlを使用してプログラムを実行するとうまくいきます。しかし、同じプログラムをindex.xhtmlで実行すると、「要求されたリソースが利用できません」という404エラーがスローされます。次のようにXHTMLではなくHTMLでないJava EE 404エラー

マイフォルダ構造は次のとおりです。私はindex.htmlを使用してプログラムを実行すると

enter image description here

、私は次のURLを使用:http://localhost:8081/index.htmlを、そしてページがHello Worldのに表示されます。 index.xhtmlを使用して実行したとき、私はhttp://localhost:8081/example2/index.xhtmlhttp://localhost:8081/index.xhtmlの両方を試しました。どちらも404エラーを出します。次のように

私のweb.xmlがある:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>*.xhtml</url-pattern> 
    </servlet-mapping> 
</web-app> 

私は複数のブラウザ(ChromeとFirefoxの)も試してみました。 XHTMLではなくHTMLではない404の理由は何ですか?

+0

すべて表示web.xml – BrunoDM

答えて

0

を解決はかなり簡単でした。 Tomcatのログをチェックしたところ、Tomcatにはjsf-apijsf-impl jarsが付属していなかったのでClassNotFoundExceptionがありました。私はlibというWEB-INFに新しいディレクトリを作成し、そこに2つのjarファイルを入れました。はい、の両方が必要です。今度はXHTMLファイルが見つけられ、404は消えます。

1

あなたは以下のコードをweb.xmlにホームページを設定できるの:だからあなたは両方を使用することができます

<display-name>NameOfProject</display-name> 

    <!-- Configuration of your home page --> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.xhtml</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

http://localhost:8081/NameOfProject/または http://localhost:8081/NameOfProject/index.xhtml

+0

これは私の問題を解決しませんが、残念ながら。もともと説明したように同じことが起こります。 – acs254

+0

あなたのページを間違った場所に置いているようです(WEB-INF)。 Webフォルダのルートにページを移動します。 – Davijr

+0

IntelliJ - プロジェクトウィザードでプロジェクトを設定した方法です。また、HTMLのようにすべてうまく動くとXHTMLの問題を解決するのはなぜでしょうか? – acs254

関連する問題