eclipse建立springMVC 簡單項目


http://jinnianshilongnian.iteye.com/blog/1594806

如何通過eclipse建立springMVC的簡單項目,現在簡單介紹一下。

工具/原料

 
  • eclipse
  • 相關jar包

方法/步驟

 
  1. 新建一個動態web項目,選擇 Dynamic Web Project 點擊 NEXT  填寫項目名稱,點NEXT  NEXT  選中Generate web.xml 選項,結束。

    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
  2. 在項目下建立相關文件夾,包括java,resources(存放spring等資源文件),view(存放動態頁面),右鍵點擊項目,修改properties -> sources 為java和resources(新建資源文件夾)

    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
  3. 引入相關jar包,如下,包括 commons-logging-1.1.1.jar;spring-beans-

    4.0.5.RELEASE.jar;spring-context-4.0.5.RELEASE.jar;spring-context-support-4.0.5.RELEASE.jar;spring-core-4.0.5.RELEASE.jar;spring-expression-4.0.5.RELEASE.jar;spring-web-4.0.5.RELEASE.jar;spring-webmvc-4.0.5.RELEASE.jar;spring-webmvc-portlet-4.0.5.RELEASE.jar等

    eclipse建立springMVC 簡單項目
  4. 修改web.xml文件,增加spring等相關內容。

    在resources目錄下新建spring目錄文件夾,在其中新建springMVC.xml,applicationContext-web.xml配置文件,編輯相關內容。

    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
  5. 在view目錄下建index.jsp,編輯頁面內容保存。修改web.xml,建歡迎頁:

     <welcome-file-list>

        <welcome-file>view/index.jsp</welcome-file>

      </welcome-file-list>

    保存。

    eclipse建立springMVC 簡單項目
  6. 建立spring controller 文件 新建class文件 ;編輯返回頁面 byebye.jsp

    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目
  7. 通過tomcat啟動,在瀏覽器輸入:http://localhost:9090/springMVC/ 即可,點擊鏈接,調用controller返回byebye頁面,至此項目建立成功。

    eclipse建立springMVC 簡單項目
    eclipse建立springMVC 簡單項目


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM