将Spring应用到servlet中

将Spring应用到servlet中

//接收表单用户

String name =request.getParameter(“username”);

//封装成User对象

User u=new U();
u.setU_username(username);

//调用service方法验证用户
UserService us =new UserServicelmpl();

//根据用户验证结果进行操作

//验证成功登陆,转发到index.jsp
request.setAttribute(a,a);
request.getDispather().forward(request,response);
//验证失败,重定向到login——page.jsp
response.sendRedirect(request.getContextPath()+"/index.jsp");

在这里插入图片描述

<配置datasource>
在这里插入图片描述

<配置dao》
在这里插入图片描述

<配置service》

Spring随项目启动

//我们在web项目中只需要一个spring容器
application域
servletcontext()生命周期随着web项目启动而建立,随着web项目关闭而销毁
//servletcontextListener可以通过监听器来达到我们的需求,在web项目创建的时候创建spring容器,销毁的时候关闭spring容器

webapplicationContextUtils.getWebApplicationContext(getServletContext());

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值