基于SSM的单点登陆05

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:p="http://www.springframework.org/schema/p"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 解析properties文件的工具类 -->
<context:property-placeholder location="classpath:*.properties"/> <!-- 扫描controller组件 -->
<context:component-scan base-package="io.guangsoft.market.controller"/> <!-- 开启注解驱动 -->
<mvc:annotation-driven /> <!-- 配置视图解析 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 资源映射 -->
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<!-- 启动spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 解决post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 启动springmvc -->
<servlet>
<servlet-name>market</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>market</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
PageController.java
package io.guangsoft.market.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; /**
* 页面跳转
*/
@Controller
public class PageController { @RequestMapping("/login")
public String showLogin(String redirect, Model model) {
model.addAttribute("redirect", redirect);
return "login";
} @RequestMapping("/register")
public String showRegister() {
return "register";
}
}
UserController.java
package io.guangsoft.market.controller; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import io.guangsoft.market.util.bean.GResult;
import io.guangsoft.market.dao.bean.TbUser;
import io.guangsoft.market.service.UserService;
import io.guangsoft.market.util.utils.CookieUtil;
import io.guangsoft.market.util.utils.GResultUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; /**
* 用户登录服务controller
*/
@Controller
@RequestMapping("/user")
public class UserController { @Autowired
private UserService userService; @Value("${REDIS_USER_SESSION_KEY}")
private String cookieName; /**
* 用户注册数据校验接口
*/
@RequestMapping(value="/check/{param}/{type}",method=RequestMethod.GET)
@ResponseBody
public Object checkData(@PathVariable String param,@PathVariable int type,String callback){
GResult result = null;
//数据校验
if(type != 1 && type != 2 && type != 3){
result = GResultUtil.fail(-1, "参数类型有误!");
}else{
//调用业务层做数据校验
result = this.userService.userParamCheck(param, type);
}
//判断是否使用jsonp调用方式
if(callback != null && callback.length() > 0){
MappingJacksonValue mapping = new MappingJacksonValue(result);
mapping.setJsonpFunction(callback);
return mapping;
}
return result;
} /**
* 用户注册接口
*/
@RequestMapping(value="/register",method=RequestMethod.POST)
@ResponseBody
public GResult userRegister(TbUser user){
try{
return this.userService.userRegister(user);
}catch(Exception e){
e.printStackTrace();
return GResultUtil.fail(-1, "注册失败. 请校验数据后请再提交数据!");
}
} /**
* 用户登录接口
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public GResult userLogin(String username,String password,HttpServletRequest request,HttpServletResponse repsonse){
try{
GResult result = this.userService.userLogin(username, password);
if(result.getgCode() == 0) {
CookieUtil.setCookie(request, repsonse, cookieName, result.getgData().toString());
}
return result;
}catch(Exception e){
e.printStackTrace();
return GResultUtil.fail(-1, e.getMessage());
}
} /**
* 根据token查询用户
*/
@RequestMapping(value="/token/{token}",method=RequestMethod.GET)
@ResponseBody
public Object findUserByToken(@PathVariable String token,String callback){
GResult result = this.userService.findUserByToken(token);
//判断是否含有jsonp
if(!StringUtils.isBlank(callback)){
MappingJacksonValue mapping = new MappingJacksonValue(result);
mapping.setJsonpFunction(callback);
return mapping;
}
return result;
}
}
基于SSM的单点登陆05的更多相关文章
- 基于SSM的单点登陆04
jdbc.properties JDBC_DRIVER=org.mariadb.jdbc.Driver JDBC_URL=jdbc:mariadb://127.0.0.1:3306/market JD ...
- 基于SSM的单点登陆01
使用SSM的Maven聚合项目 建立父项目market的pom文件 <?xml version="1.0" encoding="UTF-8"?> & ...
- 基于SSM的单点登陆03
TbUser.java和TbUserExample.java,TbUserMapper.java,TbUserMapper.xml由mybatis框架生成. generatorConfig.xml & ...
- 基于SSM的单点登陆02
pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- Spring Security 解析(六) —— 基于JWT的单点登陆(SSO)开发及原理解析
Spring Security 解析(六) -- 基于JWT的单点登陆(SSO)开发及原理解析 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把 ...
- 集成基于OAuth协议的单点登陆
在之前的一篇文章中,我们已经介绍了如何为一个应用添加对CAS协议的支持,进而使得我们的应用可以与所有基于CAS协议的单点登陆服务通讯.但是现在的单点登陆服务实际上并不全是通过实现CAS协议来完成的.例 ...
- 集成基于CAS协议的单点登陆
相信大家对单点登陆(SSO,Single Sign On)这个名词并不感到陌生吧?简单地说,单点登陆允许多个应用使用同一个登陆服务.一旦一个用户登陆了一个支持单点登陆的应用,那么在进入其它使用同一单点 ...
- ASP.NET 单点登陆
第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...
- ASP.NET在不同情况下实现单点登陆(SSO)的方法
第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...
随机推荐
- bootstrap基础学习十篇
bootstrap字体图标(Glyphicons) a.什么是字体图标 字体图标是在 Web 项目中使用的图标字体.虽然,Glyphicons Halflings 需要商业许可,但是您可以通过基于项目 ...
- 分享一个Unity3D小作品,源码地址已公布在文章开头!
Update:回复量有点大,楼主工作期间可能无暇向童鞋们发送源码,为了不让童鞋们久等,现公布源码地址. 链接: http://pan.baidu.com/s/1sjpYW4d 密码: zhp9 请注 ...
- linq依据传入数据集合查询相应子级数据
工作中经经常使用到的linq依据传入数据集合查询相应子级数据,整理共享,希望大家都能用得上,代码中doublesArray 为父节点相应ID数据集合,再依据ID数据集合查询所有子级数据. //获取缓存 ...
- Java散列和散列码的实现
转自:https://blog.csdn.net/al_assad/article/details/52989525 散列和散列码 ※正确的equals方法应该满足的的条件: ①自反性:x.equ ...
- No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available
参考地址:http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/ ...
- Angular入门(三) 引入boostrap4
1.cnpm install ngx-bootstrap bootstrap --save ※可能缺少jquery cnpm i jquery 2. 打开 angular-cli.json (项目 ...
- tomcat的虚拟目录映射常用的几种方式
我们在项目部署的时候,可以采用多种方式,接下来我们将在实际中比较常用的几种方式总结如下. 1.可以直接将我们的项目丢到tomcat的webapps目录下,这样当tomcat重启的时候,我们就可以访 ...
- delphi xe-system.json
Delphi XE10有一个对JSON处理的单元,在你需要使用JSON的单元里面引入"System.json",随后你就可以用Delphi自己的json处理类了. 普通解析 实例1 ...
- Oracle安装错误:File not found WFMLRSVCApp.ear
oracle 11g安装过程中问题:找不到WFMLRSVCApp.ear 在 oracle 11gR2 64bit 安装到window 7 64位操作系统中,安装到53%时,提示找不到WFMLRSVC ...
- fun_action
make an absolute URI from a relative one http://php.net/manual/en/function.header.php <?php /* Re ...