Skip to content

Instantly share code, notes, and snippets.

View wdfx100's full-sized avatar

wangxu wdfx100

View GitHub Profile
@wdfx100
wdfx100 / gist:6232682
Created August 14, 2013 16:18
URL类的图片下载
URL url = new URL("http://www.kaishengit.com/images/2013.jpg");
URLConnection conn =url.openConnection();
InputStream stream = conn.getInputStream();
File file = new File("F:/tupian.jpg");
OutputStream out = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(stream);
BufferedOutputStream bos = new BufferedOutputStream(out);
@wdfx100
wdfx100 / gist:6232463
Last active December 21, 2015 02:08
URL类
URL url = new URL("http://www.baidu.com");
URLConnection conn =url.openConnection();
InputStream stream = conn.getInputStream();
//字符流
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"UTF-8"));
String str = null;
StringBuffer sb = new StringBuffer();
while((str=reader.readLine())!=null){
sb.append(str);
@wdfx100
wdfx100 / gist:6200582
Created August 10, 2013 14:10
根据正则表达式查找@的用户
Pattern p = Pattern.compile("@\\w+\\s");
String str = "@tom @jerry @rose 这是我的电子邮件,给我发邮件哦[email protected]";
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
@wdfx100
wdfx100 / java
Created July 29, 2013 15:33
Spring MVC 处理请求流程
1、客户端发出请求;
2、DispatcherServlet 获取请求;
3、DispatcherServlet 查询 HandlerMapping,将请求的URL映射到一个控制器对象Controller,
并将请求分发给这个 Controller;
4、Controller 根据设计的业务逻辑处理请求;
5、完成业务逻辑的处理后,Controller 返回一个ModelAndView 给 DispatcherServlet ;
@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 匿名过滤器
@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 / 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 / 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 / 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 / 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>