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的更多相关文章

  1. 基于SSM的单点登陆04

    jdbc.properties JDBC_DRIVER=org.mariadb.jdbc.Driver JDBC_URL=jdbc:mariadb://127.0.0.1:3306/market JD ...

  2. 基于SSM的单点登陆01

    使用SSM的Maven聚合项目 建立父项目market的pom文件 <?xml version="1.0" encoding="UTF-8"?> & ...

  3. 基于SSM的单点登陆03

    TbUser.java和TbUserExample.java,TbUserMapper.java,TbUserMapper.xml由mybatis框架生成. generatorConfig.xml & ...

  4. 基于SSM的单点登陆02

    pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...

  5. Spring Security 解析(六) —— 基于JWT的单点登陆(SSO)开发及原理解析

    Spring Security 解析(六) -- 基于JWT的单点登陆(SSO)开发及原理解析   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把 ...

  6. 集成基于OAuth协议的单点登陆

    在之前的一篇文章中,我们已经介绍了如何为一个应用添加对CAS协议的支持,进而使得我们的应用可以与所有基于CAS协议的单点登陆服务通讯.但是现在的单点登陆服务实际上并不全是通过实现CAS协议来完成的.例 ...

  7. 集成基于CAS协议的单点登陆

    相信大家对单点登陆(SSO,Single Sign On)这个名词并不感到陌生吧?简单地说,单点登陆允许多个应用使用同一个登陆服务.一旦一个用户登陆了一个支持单点登陆的应用,那么在进入其它使用同一单点 ...

  8. ASP.NET 单点登陆

    第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...

  9. ASP.NET在不同情况下实现单点登陆(SSO)的方法

    第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...

随机推荐

  1. scheme 中的宏使用

    #lang scheme ( define-syntax my-when     ( syntax-rules ()       [ ( _ pred body ... )         ( if ...

  2. kvm和qemu的关系

    KVM (Kernel Virtual Machine) is a Linux kernel module that allows a user space program to utilize th ...

  3. _beginthreadex创建线程,立即执行?

    一个线程创建后,并不是立马就执行,而是等时间片到来后才执行...  C++ Code  12345678910111213141516171819202122232425262728293031323 ...

  4. 6、手把手教React Native实战之JSX入门

    React是由ReactJS与React Native组成,其中ReactJS是Facebook开源的一个前端框架,React Native是ReactJS思想在native上的体现! JSX并不是一 ...

  5. Linux下文件属性(drwxr-xr-x)详解以及(-rwxrwxrwx=777)(转)

    权限的计算是除去第一位字母开始,权限都是三个符号为一组合,其中-表没有这个权限. drwxr-xr-x的意思解释: ls -al 得到如下列表: drwxr-xr-x 4 oracle dba 409 ...

  6. 【Linux】命令学习笔记和总结

    莫名的想学习一下Linux了,因为对这方面的知识储备为0.对于命令行界面始终是零接触零了解,对一个程序员来说这几乎是致命的,所以简单了解一下. 一.教程参考 参考菜鸟教程即可: Linux 教程 | ...

  7. delphi ,1)控件根据窗口大小,一直居中显示 2)显示最大化最小化按钮控件

    一.控件根据窗口大小,一直居中显示 1)onResize:当窗体尺寸改变时发生 例子:如何使控件随窗口的放大和缩小动态改变自己的大小,使控件“保存.返回”在窗口变大变小中随着变. 在Panel调用 p ...

  8. 《挑战程序设计竞赛》2.6 数学问题-素数 AOJ0009 POJ3126 3421 3292 3641

    AOJ0009 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009 题意 求不大于n的素数个数. 思路 素数筛法可解,筛法过程中 ...

  9. Spoken English Practice(Look, That cute guy is checking me out. come on, give me a break, he's just looking around.)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/6) 英 ...

  10. 并发测试 java.lang.OutOfMemoryError: GC overhead limit exceeded Xms Xmx 阻塞请求 单节点 请求分发 负载均衡

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:705) at javax.servlet.http.HttpServlet.se ...