springmvc+maven搭建web項(xiàng)目
本文實(shí)例為大家分享了springmvc maven搭建web項(xiàng)目的具體步驟,供大家參考,具體內(nèi)容如下
1、創(chuàng)建一個(gè)maven project 為spring1
2、進(jìn)行項(xiàng)目的配置:默認(rèn)的java 1.5 在properties中選擇project facts項(xiàng)目進(jìn)行配置,反選web之后修改java環(huán)境為1.8.修改之后如下圖:
3. 配置好的工作目錄如下:
4 修改pom.xml文件
增加兩個(gè)jar包:servlet和spring webmvc
pom.xml如下:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
4. 默認(rèn)的配置文件是spring-servlet.xml ,在/web-inf下創(chuàng)建配置文件,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 配置掃描的包 --> <context:component-scan base-package="spring1.*" /> <!-- 注冊(cè)HandlerMapper、HandlerAdapter兩個(gè)映射類 --> <mvc:annotation-driven /> <!-- 訪問靜態(tài)資源 --> <mvc:default-servlet-handler /> <!-- 視圖解析器 --> <bean > <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
注:在這個(gè)默認(rèn)的配置過程中 程序會(huì)掃描spring1包中的所有的controller
5、 在src/main/java創(chuàng)建controller
package spring1; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class DemoController { @RequestMapping("/index") public String index(){ return "index"; } }
6、 在webapp目錄下創(chuàng)建index.jsp.
<html> <body> <h2>Hello World!</h2> </body> </html>
7、 部署項(xiàng)目到tomcat上,部署的內(nèi)容如下:
8、啟動(dòng)tomcat 在瀏覽器中輸入:http://localhost:8080/spring1/
總結(jié):調(diào)試了好久,終于調(diào)試出來信息啦 小小激動(dòng)一下啊
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringAOP如何修改請(qǐng)求參數(shù)列表
這篇文章主要介紹了SpringAOP如何修改請(qǐng)求參數(shù)列表問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03一文搞懂Mybatis中Mapper配置文件獲取參數(shù)的五種方式
這篇文章主要介紹了Mybatis中Mapper配置文件獲取參數(shù)的五種方式,文中通過代碼示例講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-03-03feign調(diào)用中文參數(shù)被encode編譯的問題
這篇文章主要介紹了feign調(diào)用中文參數(shù)被encode編譯的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03SpringBoot+WebSocket+Netty實(shí)現(xiàn)消息推送的示例代碼
這篇文章主要介紹了SpringBoot+WebSocket+Netty實(shí)現(xiàn)消息推送的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04JavaWeb開發(fā)之JSTL標(biāo)簽庫的使用、 自定義EL函數(shù)、自定義標(biāo)簽(帶屬性的、帶標(biāo)簽體的)
這篇文章主要介紹了JavaWeb開發(fā)之JSTL標(biāo)簽庫的使用、 自定義EL函數(shù)、自定義標(biāo)簽(帶屬性的、帶標(biāo)簽體的),需要的朋友可以參考下2017-02-02Java實(shí)戰(zhàn)之兼職平臺(tái)系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了如何利用Java編寫一個(gè)兼職平臺(tái)系統(tǒng),采用到的技術(shù)有Springboot、SpringMVC、MyBatis、ThymeLeaf等,感興趣的小伙伴可以了解一下2022-03-03