ssm实际项目中利用cookie实现快速登陆功能

本文档详细介绍了如何在SSM(Spring、SpringMVC、MyBatis)项目中通过Cookie实现快速登录功能。首先展示了配置文件spring-ws.xml的内容,接着提供了判断Cookie中是否存在用户名和密码的方法,以及获取Cookie值的方法。然后,演示了登录验证过程,如果Cookie中有值则直接跳转到主页,并使用过滤器避免用户进入登录页面,实现了无感知的快速登录体验。
摘要由CSDN通过智能技术生成

1.首先编写配置文件spring-ws.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- 自动扫描webService -->
<context:component-scan base-package="com.lanou.service" />
<!-- 定义webservice的发布接口 -->
<jaxws:endpoint id="receiveTaskNote" 
implementor="com.lanou.service.Impl.ContractHisServiceImpl" address="/ContractHisService"/>
</beans>

2. 

/**
 * 判断cookie 里面是否存在用户名和密码
 * 
 * @return
 */
public boolean isExist(HttpServletRequest request) {
// 不存在的
boolean flag = false;
Cookie[] cs = request.getCookies();
int count = 0;// 记录比较次数
 for (Cookie c : cs) {
  if (c.getName().equals("loginName")) {
  count++;
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值