2016-08-29 20 views
1

Spark Javaフレームワークには新しく、Freemarkerテンプレートエンジンを使用してhtmlファイルをレンダリングしようとしています。しかし、私はCSSとjsファイルをレンダリングできません。Spark Java Template Engineを使用してcssファイルとjsファイルをレンダリングできない

次のように私のプロジェクト構造は次のとおりです。

./pom.xml 
./src/main/java/Spark.java 
./src/main/resources/css/bootstrap.css 
./src/main/resources/js/bootstrap.min.js 
./src/main/resources/js/app.js 
./src/main/resources/templates/search.ftl 

次のように主な方法は次のとおりです。

public static void main(String[] args) { 

     BasicConfigurator.configure(); 

     staticFileLocation("/css"); 
     staticFileLocation("/Content/Images"); 
     staticFileLocation("/fonts"); 
     staticFileLocation("/js"); 

     final Configuration configuration = new Configuration(); 
     configuration.setClassForTemplateLoading(Spark.class, "/"); 

     get("/searchview", (request, response) -> { 

      StringWriter writer = new StringWriter(); 

      try { 
       Template searchTemplate = configuration.getTemplate("templates/search.ftl"); 

       searchTemplate.process(null, writer); 
      } catch (Exception e) { 
       halt(500); 
      } 

      return writer; 
     }); 
} 

そして今、私は次のURLを入力します。localhostを:4567/searchview、私のHTMLページがレンダリングされますしかし、CSSとJSはそうではありません。私のコンソールで

それは言う:INFO spark.http.matching.MatcherFilter - 要求されたルート[/css/bootstrap.min.css]は、Spark

にマッピングされていない、私は何をしないのですか?

答えて

0

その後のstaticFileLocationコールは、以前に設定した静的ファイルの場所を上書きします。 src/main/resourcesの下にpublicという名前のフォルダを作成し、css,fontsjsなどの静的フォルダをその下に置きます。最後に、静的ファイルの場所をstaticFileLocation("/public")で設定します。

関連する問題