基于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. ...
随机推荐
- ubuntu14.04安装vmware workstation
0) Do the basic system installation of Ubuntu 14.04 LTS (Server or Desktop) 1) wget the installer wg ...
- Android上传图片(PHP服务器)
原理 Android客户端模拟一个HTTP的Post请求到服务器端,服务器端接收相应的Post请求后,返回响应信息给给客户端. PHP服务器 <?php move_uploaded_file($ ...
- TArray数组
TArray<int32> arr; arr.Init(,); ; index < arr.Num(); index++) { FString str = FString(" ...
- Python 实现购物商城,含有用户入口和商家入口
这是模拟淘宝的一个简易的购物商城程序. 用户入口具有以下功能: 登录认证 可以锁定用户 密码输入次数大于3次,锁定用户名 连续三次输错用户名退出程序 可以选择直接购买,也可以选择加入购物车 用户使用支 ...
- .net webapi项目跨域问题及解决方案
问题: 1.项目完成,部署到不同的iis版本上,跨域访问有的通有的不通 解决办法: 1.将复杂请求改为简单请求 2.代码中去掉所有跨域设置,配置中添加或修改节点 <system.webServe ...
- 再论IBatisNet + Castle进行项目的开发
随着项目的进展,Castle和IBatisNet给我的惊喜更多.Com+很重,不需要分布式的中小项目慎用,NHibernate虽好,NHibernate的2005-9-20发布了最新版本1.0-rc1 ...
- 《从零开始学Swift》学习笔记(Day60)——Core Foundation框架
原创文章,欢迎转载.转载请注明:关东升的博客 Core Foundation框架是苹果公司提供一套概念来源于Foundation框架,编程接口面向C语言风格的API.虽然在Swift中调用这种C语言风 ...
- 手动爬虫之淘宝笔记本栏(ptyhon3)
1.这次爬虫用到了之前封装的Url_ProxyHelper类,源代码如下 import urllib.request as ur class Url_ProxyHelper: def __init__ ...
- slave_exec_mode参数对主从复制的影响
主从复制中常会遇到的问题就是1062主键重复.1032 slave上相关记录没找到 如果在读写分离的架构中,slave同步失败会对业务造成很大的影响的(比如主写入了一条数据,从上无法读取到这样对业务影 ...
- Spoken English Practice( let me just pull over(pull,give))
绿色:连读: 红色:略读: 蓝色:浊化: 橙色:弱读 下划线_为浊化 口语蜕变(2017/6/26) ...