Eclipse搭建SpringMVC web项目(非maven方式)

1.新建web项目
这里写图片描述
2.选择对应的配置,注意红色框内圈出来的,填写或选择对应版本
这里写图片描述
然后下一步,注意选择直接生成web.xml文件
这里写图片描述
3.导入jar包,可以直接去对应的官网下载,或者直接到正文的网站下载,我已经整理并上传了
https://download.csdn.net/download/itzhangminpeng/10312343
这里写图片描述
4.新建spirngmvc.xml配置文件,并进行编辑,代码如下:

<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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">


    <context:component-scan base-package="com.zmp.springmvc"></context:component-scan>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

这里写图片描述
这里写图片描述
5.编辑web.xml文件,代码如下:

  <display-name>SpringMVCProject</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
        <servlet-name>springDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
  </servlet>

  <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
  </servlet-mapping>

这里写图片描述
6.新建Controller层类,注意返回页面路径及名称的时候要视图层保持一致(下一步建页面),代码如下:
package com.zmp.springmvc;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* @author zmp
* @desc 后台控制类,也没啥好注释的
* @date 2018.3.27
*/

@Controller
@RequestMapping(“/mvc”)
public class FirstMVCController{

/*
 * 返回页面
 */
@RequestMapping("/firstPage")
public String firstMVCPage(HttpServletRequest request){
    request.setAttribute("msg", "返回页面的数据");
    return "firstPage";
}

}

这里写图片描述

7.建返回页面,注意和后台方法返回的页面名称保持一致,否则会报404,接收后台${msg}注意和后台返回变量保持一致
这里写图片描述
8.创建项目index页
这里写图片描述
9.项目搭建完毕,运行起来,看看效果
这里写图片描述
这里写图片描述
10.如果有朋友需要设置不带项目名访问,双击tomcat,操作方式如下:
这里写图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

民鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值