首先, 安装eclipse和tomcat, 这里我下载的是tomcat9.0版本64位免安装的:地址https://tomcat.apache.org/download-90.cgi

免安装的如何启动和关闭Tomcat呢?鼠标双击就可以了

下面,打开eclipse: 导航栏File->New->Dynamic Web Project, 填写好project name,有人说过,给项目起名字一定要认真,就像给自己孩子起名字一样,这样才能又唯一标识!这里由于是第一个Spring项目,起名为SpringDemo, 如下图所示:

点击New Runtime选择你的Tomcat, 这里我选择最新版的9.0:

点击Next, 选择Tomcat的位置:D:\Tomcat\apache-tomcat-9.0.1-windows-x64\apache-tomcat-9.0.1, JRE选择你安装的jre即可, 点击finish即可

配置如下, 点击finish完成

完成后如下:

下面就是要下载Spring jar包了,这里给一个链接,根据该链接的一步一步下载即可: http://www.cnblogs.com/leavescy/p/7657476.html

将刚才的jar包放到E:\javaEE\javaWorkplace\SpringDemo\WebContent\WEB-INF\lib(即你工程的目录下),然后重启eclipse,就会看到

创建相关配置文件和控制文件:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" > <display-name>SpringDemo</display-name> <!-- 配置Spring MVC分发器,拦截所有请求 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> </web-app>

springmvc-servlet.xml

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- 开启注解模式驱动 --> <!-- 扫包 --> <context:component-scan base-package="com.springmvc.controller">
</context:component-scan>
<context:annotation-config/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 指定页面存放的路径 -->
<property name="prefix" value="/WEB-INF/pages/"></property>
<!-- 文件的后缀 -->
<property name="suffix" value=".jsp"></property> </bean> </beans>

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- Empty --> </beans>

ViewController.java

package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class ViewController {
@RequestMapping(value="/hello")
public String hello(Model model) { model.addAttribute("greeting", "Hello Spring MVC"); return"index"; }
}

index.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${greeting}</title>
</head>
<body>
恭喜,web项目已经成功搭建!
</body>
</html>

右键项目->Run As->Run on Server:

表示没有错误, 此时在浏览器中输入:http://localhost:8080/SpringDemo/hello

此时,表示项目成功!

注意: 关于免安装的Tomcat的配置,请参考:http://www.cnblogs.com/leavescy/p/7676262.html

maven版和非maven版的最大区别在于Tomcat的启用方式!

最新文章

  1. WP8.1 RT 生命周期详解‏‏‏‏‏‏‏‏‏‏‏‏‏
  2. css知多少(5)——选择器
  3. 数据库连接池之Proxool使用
  4. Pycharm设置
  5. 计算机网络及TCP/IP知识点(全面,慢慢看)
  6. 51nod 棋盘问题(博弈论)
  7. 【暑假】[深入动态规划]UVa 1380 A Scheduling Problem
  8. 万网免费主机wordpress快速建站教程-万网主机申请
  9. sql server 查询日期中的常用语句, 例如本周第一天, 年内的第几周,有用
  10. sourceforge软件下载方式
  11. Couldn&#39;t read row 0, col -1 from CursorWindow
  12. &lt;libxml2/tree.h&gt; file not found
  13. 新生命组件XAgent使用心得
  14. SVN 、Git、Github的使用
  15. Angular2入门:TypeScript的类型 - 类型、null、undefined
  16. flask模板的基本用法(定界符、模板语法、渲染模板),模板辅助工具(上下文、全局对象、过滤器、测试器、模板环境对象)
  17. 题解——牛客网OI赛制测试赛2
  18. Linux简单了解
  19. C#Unit单元测试之读取Web.config文件
  20. JSP中四种传递参数中文乱码问题

热门文章

  1. 安装vs2013提示必须安装ie10的解决办法
  2. win7 dos窗口模拟帧刷新
  3. u-boot剖析(一)----Makefile分析
  4. POJ 2923 Relocation(01背包+状态压缩)
  5. UVA 12905 Volume of Revolution (几何,微积分)
  6. HDU 5090 Game with Pearls (贪心)
  7. fork新建进程
  8. python_90_hashlib模块
  9. Kafka 完全分布式集群环境搭建
  10. java,求1-100以内所有偶数的和。