Skip to content

Instantly share code, notes, and snippets.

View wdfx100's full-sized avatar

wangxu wdfx100

View GitHub Profile
@wdfx100
wdfx100 / Crop.java
Last active December 16, 2015 07:58
#上传头像功能#
//jar:ImageUtil.jar filters-2.0.235.jar
//jquert.jcrop.js jcrop.css
<img alt="" src="http://www.wdfx100.com/upload/${fileName }">
<form action="jcrop" method="post">
<input type="hidden" name="fileName" value="${fileName}">
<input type="hidden" name="x1" id="x">
<input type="hidden" name="y1" id="y">
<input type="hidden" name="x2" id="x2">
<input type="hidden" name="y2" id="y2">
<input type="submit" value="剪裁"/>
@wdfx100
wdfx100 / download.java
Last active December 16, 2015 07:59
#文件下载#
//注意要点
//1.文件格式的设置
//2.文件名中中文的设置
//3.文件大小的设置
//4.设置一个相应的头 Servlet download file:搜 键:文件的描述 值:对应的文件
response.setContentType("application/pdf");//设置文件格式
String fileName = "第一章.pdf";
File file = new File("I:/test/upload","第一章.pdf");//下载文件的路径及名称
response.setContentLength(new Long(file.length()).intValue());//进度条的操作,提示完成进度
@wdfx100
wdfx100 / TokenUtil.java
Created April 17, 2013 09:50
#表单验证token#
//token.servlet→jsp→servlet→jsp结果页
public class TokenUtil {
public static void createToken(HttpServletRequest request,HttpServletResponse response){
UUID uuid = UUID.randomUUID();
String token = uuid.toString();
request.getSession().setAttribute("session_token",token);
request.setAttribute("request_token", token);
@wdfx100
wdfx100 / gist:5403133
Created April 17, 2013 09:55
#验证码#
jar:3
jcaptcha-2.0-alpha-1-SNAPSHOT.jar
jcaptcha-api-1.0.jar
jcaptcha-integration-simple-servlet-2.0-alpha-1-SNAPSHOT.jar
<form action="pay2" method="post">
<input type="hidden" name="token" value="${requestScope.request_token }"/>
输入支付金额:<input type="text" name="money"/><br>
请输入验证码:<input type="text" name="code" value=""/><br/>
<img alt="验证码" src="/jcaptcha.jpg" id="img">
@wdfx100
wdfx100 / gist:5403169
Created April 17, 2013 10:01
#加密#
jar
commons-codec-1.6.jar
sha.js
<form action="login" method="post" class="formgo">
<c:choose>
<c:when test="${param.error=='1001' }">
<p>用户名或密码错误 </p>
</c:when>
@wdfx100
wdfx100 / gist:5404104
Created April 17, 2013 13:02
#cookie的添加#
login.java:
if(rm != null){
Cookie usernameCookie =new Cookie("username", username);
usernameCookie.setDomain("www.wdfx100.com");
usernameCookie.setPath("/");
usernameCookie.setMaxAge(60*60*24);
Cookie passwordCookie =new Cookie("password", password);
passwordCookie.setDomain("www.wdfx100.com");
passwordCookie.setPath("/");
@wdfx100
wdfx100 / logout.java
Created April 17, 2013 13:27
#删除cookie#安全退出
//让session过期
request.getSession().invalidate();//安全退出,强制Session过期
//删除cookie
Cookie[] cookies = request.getCookies();
if(cookies!=null){
for(Cookie c:cookies){
if("username".equals(c.getName())||"password".equals(c.getName())){
c.setMaxAge(0);
c.setPath("/");
c.setDomain("www.wdfx100.com");
@wdfx100
wdfx100 / java
Created May 12, 2013 02:26
#ajax#
function createXMLHttpRequest(){
var xmlHttp;//创建ajax引擎
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
@wdfx100
wdfx100 / java
Created May 13, 2013 04:08
#第三方api组件的应用#apache HttpComponents HTTP client的使用
HttpClient client = null;
try {
client = new DefaultHttpClient();//获得一个代理
HttpGet get = new HttpGet("http://www.youdao.com/smartresult-xml/search.s?type=id&q="+code);//获得请求
HttpResponse response = client.execute(get);//获得响应
InputStream stream = response.getEntity().getContent(); //从内存角度,获得一个输入流
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"GBK"));
//获得的文字,以字符流的形式输出【图片、MP3,文件用字节流输出】
StringBuilder sb = new StringBuilder();
@wdfx100
wdfx100 / shiro
Last active December 19, 2015 12:39
#shiro#urls的配置
/index.html = anon
/user/create = anon
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]
过滤器名称 过滤器类 描述
anon org.apache.shiro.web.filter.authc.AnonymousFilter 匿名过滤器