SpringMVC教程(一):环境搭建

环境:eclipse+tomcat8.5
第一步:jar准备(基础包):
commons-logging-1.1.1.jar
jstl-1.2.jar
spring-aop-4.0.4.RELEASE.jar
spring-aspects-4.2.6.RELEASE.jar
spring-beans-4.0.4.RELEASE.jar
spring-context-4.0.4.RELEASE.jar
spring-core-4.0.4.RELEASE.jar
spring-expression-4.0.4.RELEASE.jar
spring-web-4.0.4.RELEASE.jar
spring-webmvc-4.0.4.RELEASE.jar
第二步:web.xml文件配置拦截器
servlet-name可以随意命名,上下必须一致在这里插入图片描述
第三步:配置springmvc.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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
   <!-- 开启注解驱动 -->
    <mvc:annotation-driven></mvc:annotation-driven>
    
     <mvc:default-servlet-handler />
    
    <!-- 扫描java文件路径 -->
	<context:component-scan base-package="cn.***.springmvc"></context:component-scan>
    <bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- 前缀   跳转页面目录为WebContent/views/下 -->
		<property name="prefix" value="/views/"></property>
		<!-- 后缀   跳转页面为jsp文件 -->
		<property name="suffix" value=".jsp"></property>
	</bean>  
</beans>

第四步:控制类编写

@Controller
@RequestMapping("/")
public class YgglController {
	
	@Resource(name="ygglService")
	private YgglService ygglService;
	
	@RequestMapping(value="login",method=RequestMethod.POST)//,method=RequestMethod.POST
	public String hello(String user,String pass) {
		System.out.println("login"+user);
		System.out.println("login"+ygglService.getConn());
		//返回要调用的jsp页面
		return "hello";
	}

}

jsp

<form action="login" method="post">
账号:<input name="user" />
密码:<input type="password" name="pass" />
<button>登陆</button>
</form>

截止一个简单的用户登陆springMVC的小案例就搭建完成

–菜鸟升阶路上学习记录,欢迎各位大牛批评指正!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值