java简单mvc实验小项目_【实验室】建立springMVC的简单项目

准备:

Eclipse、Tomcat、JDK

开始:

新建一个动态web项目,选择 Dynamic Web Project 点击 NEXT  填写项目名称,点NEXT  NEXT  选中Generate web.xml 选项,结束。

5c8902c401e528aa0b336992962ce337.gif

46fc6057ef17711c2028458efbe53eca.gif

在项目下建立相关文件夹,包括java,resources(存放spring等资源文件),view(存放动态页面),右键点击项目,修改properties -> sources 为java和resources(新建资源文件夹)

7c9dfde249550773adeba28ee5a63005.gif

引入相关jar包,如下:

d0eb80488aa59ef39ce01088d4f8d97c.gif

web.xml

eonhr

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:applicationContext-web.xml

apiServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springMVC.xml

1

apiServlet

/

view/index.jsp

404

/WEB-INF/view/error/404.jsp

src/resources下新建xml文件

1、applicationContext-web.xml

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

2、springMVC.xml

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

到上面,简单的环境已经搭建好了。

测试:

建立controller:

packagecom.eon.hr.test;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.RequestMapping;

@Controller

@RequestMapping("/test")public classTestAction {

@RequestMapping(value="byebye")publicString byeTest(){return "/test/test_bye";

}

}

返回页面 /test/test_bye.jsp:

test

首页index.jsp:

Index

bye

访问:

http://127.0.0.1:8080/eonhr/

DEMO:点击查看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值