安装+java+mvc_springmvc+maven搭建web项目

本文实例为大家分享了springmvc maven搭建web项目的具体步骤,供大家参考,具体内容如下

1、创建一个maven project 为spring1

2、进行项目的配置:默认的java 1.5 在properties中选择project facts项目进行配置,反选web之后修改java环境为1.8.修改之后如下图:

7ff26eb9eb52d3ac2d23f5b92a6ebb53.png

3. 配置好的工作目录如下:

bbfd5122f2cf5d2bc2e5fae322bcba0d.png

4 修改pom.xml文件

增加两个jar包:servlet和spring webmvc

pom.xml如下:

/p>

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd" >

spring

org.springframework.web.servlet.DispatcherServlet

spring

/

4. 默认的配置文件是spring-servlet.xml ,在/web-inf下创建配置文件,内容如下:

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">

>

注:在这个默认的配置过程中 程序会扫描spring1包中的所有的controller

5、 在src/main/java创建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目录下创建index.jsp.

Hello World!

7、 部署项目到tomcat上,部署的内容如下:

ce16317a152926ce87f9956b547dad05.png

8、启动tomcat 在浏览器中输入:http://localhost:8080/spring1/

b8b036e6e040c1e884c5fe99ec6056fd.png

总结:调试了好久,终于调试出来信息啦 小小激动一下啊

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值