首页 技术 正文
技术 2022年11月12日
0 收藏 705 点赞 4,394 浏览 2288 个字

1、创建一个maven project 为spring1

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

springmvc+maven搭建web项目

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

springmvc+maven搭建web项目

4
修改pom.xml文件

增加两个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. 默认的配置文件是spring-servlet.xml ,在/web-inf下创建配置文件,内容如下:

<?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.*” />

<!– 注册HandlerMapper、HandlerAdapter两个映射类 –>
    <mvc:annotation-driven />

<!– 访问静态资源 –>
    <mvc:default-servlet-handler />

<!– 视图解析器 –>
    <bean
        class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
        <property name=”prefix” value=”/WEB-INF/”></property>
        <property name=”suffix” value=”.jsp”></property>
    </bean>

</beans>

注:在这个默认的配置过程中 程序会扫描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.

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
7、 部署项目到tomcat上,部署的内容如下:

springmvc+maven搭建web项目

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

springmvc+maven搭建web项目

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,154
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,623
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,467
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,239
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,874
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,042