springmvc练习

本练习示例完整代码下载地址:http://download.csdn.net/download/zhaoqingkaitt/9308245


1、开发环境:

Eclipse版本:Version: Mars Release (4.5.0)
jdk版本:1.7
tomcat:6.0

2、新建动态web项目(SpringMvc01),导入如下jar包

commons-logging-1.1.1.jar
spring-aop-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-context-support-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar

3、web.xml配置

<!--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>

4、在WEB-INF下新建文件夹jsp,在jsp文件夹中新建hello.jsp文件


5、新建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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.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-4.0.xsd">
<!--自动扫描-->
<context:component-scan base-package="test"></context:component-scan>
<!--视图转发配置 前缀+return+后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--请求前缀-->
<property name="prefix" value="WEB-INF/jsp/"></property>
<!--请求后缀-->
<property name="suffix" value=".jsp"></property>
</bean>
</beans>


7、新建java文件(myController.java),内容如下:

package test;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
http://localhost:8080/SpringMvc01/hello
 * @author zhtt
 *
 */
@Controller
//@RequestMapping("/mvc")
public class mvcController {

	@RequestMapping("/hello")
	public String hello() {
		return "hello";
	}
}

8、项目结构图如下:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值