使用Myeclipse2015构建SpringMVC项目
1.新建web project
2.右键项目,给项目添加spring框架如图,不需要勾选任何一个选项。
3.在WebRoot/WEB-INF目录下添加web.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<!-- <load-on-startup>1</load-on-startup> -->
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
servlet模块添加了springmvc的调度器,如果需要改springmvc的配置文件的名字,可以更改springmvc-servlet.xml这个名字为指定名字。
servlet-mapping连接了这个servlet,并能够定义url-pattern,一般使用/而不是/*。
4.在src目录下添加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: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.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">
<!-- scan the package and the sub package -->
<context:component-scan base-package="com.controller"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>
base-package指定你的controller所在的包,prefix和suffix分别指定了view所在的位置和后缀,这个配置文件连接了controller和view。
5.新建controller,所在包应为springmvc-servlet.xml中指定的base-package
结构如下:
内容如下:
package com.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/Hello")
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
6.新建view,所在位置应为springmvc-servlet.xml中的prefix,后缀为指定后缀,名称与controller中返回的字符串相同。
内容自拟。
至此,一个springmvc的hello world项目配置完毕。
使用Myeclipse2015构建SpringMVC项目的更多相关文章
- Eclipse的maven构建一个web项目,以构建SpringMVC项目为例
http://www.cnblogs.com/javaTest/archive/2012/04/28/2589574.html springmvc demo实例教程源代码下载:http://zuida ...
- 使用Eclipse maven构建springmvc项目
Eclipse maven构建springmvc项目 Listener 监听器 架构 使用Log4J监控系统日志邮件警报 2014-12-16 13:09:16 控制器在完成逻辑处理后,通常会产生一些 ...
- maven构建springmvc项目
1.Eclipse中 NEW ->OTHER->Maven->maven project 2.选择项目路径 3.选择项目类型->next->输入groupid和artif ...
- 利用Eclipse构建SpringMVC项目
简述 SpringBoot对Spring的的使用做了全面的封装,使用SpringBoot大大加快了开发进程,但是如果不了解Spring的特性,使用SpringBoot时会有不少问题 目前网上流传使用I ...
- SpringMVC拓展——利用maven构建springMVC项目
一.构建项目结构 首先需要构建一个符合目录结构的maven项目 file->new->maven project,勾选 create a simple project->next / ...
- Eclipse maven构建springmvc项目
原文地址: http://www.cnblogs.com/fangjins/archive/2012/05/06/2485459.html 一.背景介绍 对于初学者,用maven构建项目并不是一件容易 ...
- 本次我们使用idea构建springmvc项目
该案例的github地址:https://github.com/zhouyanger/demo/tree/master/springmvcdemo1 1.首先我们可以创建maven项目,file-&g ...
- 在Eclipse中使用Maven构建SpringMVC项目
环境搭建 安装JDK, Eclipse, Tomcat等 – 请参考网上常见攻略. 安装Maven: 下载需要的Maven 版本( http://maven.apache.org/download.c ...
- JavaWeb之Eclipse中使用Maven构建SpringMVC项目
为了学习spring和maven我这也是拼了老命了,光使用maven配置springmvc我花了上周一周的时间,下班回来就搞,一直有bug,一个bug接着一个,昨天一整天都在解决配置的问题,让大学同学 ...
随机推荐
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十)
打开Arm.h,在其接口中添加一个新方法: -(void)armShoot; 接下来在Arm.m中实现该方法: -(void)armShoot{ CGPoint startPoint = [self ...
- Touch Handling in Cocos2D 3.x(三)
取得触摸位置 最有趣的部分是触摸的位置.接下来我们将使用触摸位置在玩家每次点击的屏幕位置上添加精灵.为了完成这项功能我们需要修改touchBegan的实现,替换旧的代码如下: - (void)touc ...
- 取消选中单选框radio的三种方式
作者: 铁锚 日期: 2013年12月21日 本文提供了三种取消选中radio的方式,代码示例如下: 本文依赖于jQuery,其中第一种,第二种方式是使用jQuery实现的,第三种方式是基于JS和DO ...
- 【翻译】对于Ext JS 5,你准备好了吗?
原文:Are You Ready for Ext JS 5? Ext JS 5:准备升级 对于Ext JS 5加入Sencha的大家庭,我们感到非常高兴!作为一个主要版本,在Ext JS 5引入了一堆 ...
- 华为机试题【13】-wave数组找字母游戏
题目描述: Word Maze 是一个网络小游戏,你需要找到以字母标注的食物,但要求以给定单词字母的顺序吃掉.如上图,假设给定单词if,你必须先吃掉i然后才能吃掉f. 但现在你的任务可没有这么简单,你 ...
- 网络小白之WAN与LAN的区别
剑指Offer--网络小白之WAN与LAN的区别 基本作用 wan接口是外网接口,是用来连接互联网或局域网等外部网络的. lan接口是内网接口,是用来连接计算机终端或其他路由器等终端设备的. 举例 w ...
- ORM对象关系映射之GreenDAO高级用法
CRUD 增加: dao.insert(Student entity);//添加一个 dao.insertInTx(Student... entity);//批量添加 删除: dao.deleteBy ...
- STL - miltimap(可重映射)
#include <iostream> #include <map> #include <string> using namespace std; //Multim ...
- STL算法设计理念 - 函数适配器
1)函数适配器的理论知识 2)常用函数函数适配器 标准库提供一组函数适配器,用来特殊化或者扩展一元和二元函数对象.常用适配器是: 1.绑定器(binder): binder通过把二元函数对象的一个实参 ...
- android4.2添加重启菜单项
本文主要是针对android4.2关机菜单添加重启功能 A.关机提示 android4.2/frameworks/base/policy/src/com/android/internal/policy ...