java - springMVC配置的controller无法返回jsp文件
迷茫
迷茫 2017-04-18 10:54:02
0
4
1196

当启动完tomcat后,它首先展示的是index.jsp ,当我输入http://localhost:8080/Spring_no_2/时,出现

HTTP Status 404 – Not Found Type Status Report Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
  1. 根据spring in action中的springMVC这一章中的demo进行测试,环境是mac下的Ideallij,jkd1.8,tomcat9

  2. 配置好了springMVC,相关的xml文件并且启动tomcat后(省略了配置静态资源和SpitterService类),无法通过访问url使controller返回在WEB-INF/views中的jsp文件

以下是代码文件

web.xml

   contextConfigLocation /WEB-INF/applicationContext.xml   org.springframework.web.context.ContextLoaderListener   spitter org.springframework.web.servlet.DispatcherServlet 1   spitter /  

spitter-servlet.xml

             

controller

package com.springmvc.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * Created by han on 29/3/2017. */ @Controller public class HomeController { // public static final int DEAFAULT_SPITTLES_PER_PAGE = 25; public HomeController() { System.out.println("-------HomeController init-------"); } @RequestMapping("/") public String showHomePage() { System.out.println("-------showHomePage Method show-------"); return "home"; } }

我的文件结构是

请问为什么无法使home.jsp呈现出来?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全員に返信 (4)
伊谢尔伦

問題が見つかりました。ディレクトリと Tomcat の設定はすべて正しいです。
しかし、web.xml の次のコードのせいで

リーリー

その結果、監視設定ファイルは spitter-servlet.xml の設定を読み取れません。
解決策は 2 つあります。

最初:

spitter-servlet.xml と applicationContext.xml 内の Bean およびその他の設定が読み取られるように、spitter-servlet.xml のアドレスを に追加します。 Spring in action 第 4 版で説明したように、DispatcherServlet はコントローラー、ビュー リゾルバー、ハンドラー マッピングなどの Web コンポーネントを含む Bean をロードすることが期待されますが、ContextLoaderListener はアプリケーション内の他の Bean をロードすることが期待されます。これらの Bean は通常、中間層です。
構成の異なる部分を処理するために 2 つの異なる構成ファイルがセットアップされます

2番目:

リーリー

いいねを押す+0
    大家讲道理

    親愛なる -------showHomePage メソッド show------バックグラウンドで印刷されますか?

    いいねを押す+0
      Peter_Zhu

      まず、Tomcat の設定が正しいかどうかを確認します。
      localhost:8080 に正常にアクセスできますか?
      showHomePage メソッドをもう一度見てください

      いいねを押す+0
        刘奇

        デフォルトのプロジェクト構造 Web レイヤーは webapp ディレクトリを使用します。tomcat にデプロイされたプロジェクトの WEB-INF/views ディレクトリに home.jsp が実際に存在するかどうかを確認できます。

        いいねを押す+0
          最新のダウンロード
          詳細>
          ウェブエフェクト
          公式サイト
          サイト素材
          フロントエンドテンプレート
          私たちについて 免責事項 Sitemap
          PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!