Skip to content

Instantly share code, notes, and snippets.

@qlong8807
qlong8807 / JSON Web Token(JWT)
Created April 18, 2018 02:03
JSON Web Token(JWT) - 在Web应用间安全地传递信息
一个JWT实际上就是一个字符串,它由三部分组成,头部、载荷与签名。
头部用于描述关于该JWT的最基本的信息,例如其类型以及签名所用的算法等。这也可以被表示成一个JSON对象。
例如:{"typ": "JWT","alg": "HS256"},对其进行base64编码后得到eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9。
载荷也用json表示:
{
"iss": "John Wu JWT",
"iat": 1441593502,
"exp": 1441594722,
"aud": "www.example.com",
"sub": "[email protected]",
@qlong8807
qlong8807 / InitLibraryPath.java
Last active April 23, 2018 03:11
web项目启动前Listener,把sigar加入java.library.path
1.在web.xml中添加监听
<listener>
<listener-class>com......listener.InitLibraryPath</listener-class>
</listener>
2.读取src/main/resources/sigar目录下的所有内容
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.google.common.io.Resources;
@qlong8807
qlong8807 / MyFtpUtil.java
Created April 27, 2018 07:37
实现FTP下载和FTP备份
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.log4j.Logger;
@qlong8807
qlong8807 / 邮我
Created July 27, 2018 07:01
使用邮我
明文显示邮箱:
https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&[email protected]
使用QQ邮箱生成的代码:
<a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=lO7t_Mvg89Ty__z59f34uvf7_Q" style="text-decoration:none;"><img src="http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_02.png"/></a>
@qlong8807
qlong8807 / LoggingAspect.java
Created November 22, 2018 02:07
日志拦截器,打印方法进出详细信息
import io.github.jhipster.config.JHipsterConstants;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
@qlong8807
qlong8807 / java启动.sh
Created November 22, 2018 07:43
一个启动Java程序的SH脚本
#!/usr/bin/env bash
if [ ! -n "${LIQUIBASE_HOME+x}" ]; then
# echo "LIQUIBASE_HOME is not set."
## resolve links - $0 may be a symlink
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
@qlong8807
qlong8807 / spring下载文件名乱码.java
Created December 4, 2018 03:13
spring下载文件,解决中文文件名乱码问题
response.setCharacterEncoding(request.getCharacterEncoding());
response.setContentType(MediaType.APPLICATION_OCTET_STREAM.toString());
String realFileName = URLEncoder.encode(realFileName, StandardCharsets.UTF_8.toString());
// 解决中文文件名乱码关键行
response.setHeader("Content-Disposition", "attachment; filename=\"" + realFileName + "\"; filename*=utf-8''" + realFileName);
Path path = Paths.get(filePath+filename);
Files.copy(path, response.getOutputStream());
response.flushBuffer();
//1当普通调用时,一般跳转到自定义的错误页面。
//2当ajax调用时,可返回约定的数据对象,方便页面统一处理。
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@qlong8807
qlong8807 / SpringContextUtil.java
Created December 19, 2018 10:01
java代码获取Spring容器中的bean
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext; // Spring应用上下文环境
/*