朱杰兵blog

jonhney'blog
posts - 140, comments - 1, trackbacks - 0, articles - 0

sql

两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

删除重复记录
delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)

posted @ 2015-03-12 13:53 朱杰兵 阅读(84) | 评论 (0)编辑 收藏

String,StringBuffer和StringBuilder

    这个问题也比较常见。在进行字符串拼接处理的时候,String通常会产生多个对象,而且将多个值缓存到常量池中。例如:

    String a=“a”;

    String b=“b”;

    a=a+b;

    这种情况下jvm会产生“a”,“b”,“ab”三个对象。而且字符串拼接的性能也很低。因此通常需要做字符串处理的时候尽量采用StringBuffer和StringBuilder来。



ArrayList和LinkedList的选择

    这个问题比较常见。通常程序员最好能够对list的使用场景做出评估,然后根据特性作出选择。ArrayList底层是使用数组实现的,因此随机读取数据 会比LinkedList快很多,而LinkedList是使用链表实现的,新增和删除数据的速度比ArrayList快不少。



包装类和基本类型的选择

    在代码中,如果可以使用基本数据类型来做局部变量类型的话尽量使用基本数据类型,因为基本类型的变量是存放在栈中的,包装类的变量是在堆中,栈的操作速度比堆快很多

posted @ 2015-03-11 09:33 朱杰兵 阅读(115) | 评论 (0)编辑 收藏

第一步:
去除eclipse的JS验证:
将windows->preference->Java Script->Validator->Errors/Warnings->
Enable Javascript Sematic validation前面的勾去掉;

第二步:
右键项目 -> properties -> Builders 去掉JavaScript Validator 前面的勾

posted @ 2015-03-10 11:41 朱杰兵 阅读(1951) | 评论 (0)编辑 收藏

window.open 中文乱码问题
JS中使用window.open("url param="+paramvalue)传递参数出现乱码,提交的时候,客户端浏览器URL中显示参数是正确的,但是传到了服务器端是是乱码。这种情况下需要在客户端对该参数进行编码,然后在服务器端解码即可。

1、JS客户端编码

var selStr=document.getElementsByName('selStr')[0].value;
    selStr=encodeURI(encodeURI(selStr));
    window.open('printWindow.do bm=j&selStr='+selStr+'');

注意:编码的时候需要使用两次encodeUri,写一个就是????号,写两个则输出: %4d%5a这种

2、服务器端解码:

String tempSelStrs=request.getParameter("selStr").toString();

String selStr=java.net.URLDecoder.decode(tempSelStrs,"UTF-8");

posted @ 2015-03-07 17:35 朱杰兵 阅读(1287) | 评论 (0)编辑 收藏

当eclipse已经安了一个tomcat,再安多个的时候,new server   ,
server location选择第三个 use custom location (does not modify tomcat installation)
右面的ports 三个都改成跟已有的tomcat端口不一样

posted @ 2015-03-05 17:20 朱杰兵 阅读(153) | 评论 (0)编辑 收藏

1. ps -ef | grep tomcat  查看进程
2. kill -9   xxx  杀掉指定的进程
3.  cd /...  到bin目录  
4../startup.sh & tail -f ../logs/catalina.out   或者

./catalina.sh run

(这样有个问题,当关闭客户端的时候,服务也会停掉)

解决办法,在bin目录下执行完./startup.sh   后,紧接着 在执行 tail -f ../logs/catalina.out  速度要快,不然看不到日志



进到logs下
rm -rf catalina.out
../bin/startup.sh
tail -f catalina.out

posted @ 2015-03-05 17:16 朱杰兵 阅读(129) | 评论 (0)编辑 收藏

  1. import com.alibaba.fastjson.JSONObject;  
  2.   
  3.   
  4. /** 
  5.  * Created by wangzhenfei on 14-4-15. 
  6.  */  
  7. public class FastJsonTest {  
  8.     public static void main(String[] args){  
  9.         String jsonStr = "{\"JACKIE_ZHANG\":\"张学友\",\"ANDY_LAU\":\"刘德华\",\"LIMING\":\"黎明\",\"Aaron_Kwok\":\"郭富城\"}" ;  
  10.   
  11.   
  12.         //做5次测试  
  13.         for(int i=0,j=5;i<j;i++)  
  14.         {  
  15.            JSONObject jsonObject = JSONObject.parseObject(jsonStr) ;  
  16.            for(java.util.Map.Entry<String,Object> entry:jsonObject.entrySet()){  
  17.                System.out.print(entry.getKey()+"-"+entry.getValue()+"\t");  
  18.            }  
  19.             System.out.println();//用来换行  
  20.         }  
  21.     }  
  22. }  

运行结果:
  1. LIMING-黎明 Aaron_Kwok-郭富城JACKIE_ZHANG-张学友ANDY_LAU-刘德华  
  2. Aaron_Kwok-郭富城 ANDY_LAU-刘德华LIMING-黎明JACKIE_ZHANG-张学友  
  3. Aaron_Kwok-郭富城 JACKIE_ZHANG-张学友ANDY_LAU-刘德华LIMING-黎明  
  4. LIMING-黎明 ANDY_LAU-刘德华JACKIE_ZHANG-张学友Aaron_Kwok-郭富城  
  5. JACKIE_ZHANG-张学友 LIMING-黎明ANDY_LAU-刘德华Aaron_Kwok-郭富城  


解决办法:定义为JSONArray,代码如下:

  1. import com.alibaba.fastjson.JSONArray;  
  2.   
  3. /** 
  4.  * Created by wangzhenfei on 14-4-15. 
  5.  */  
  6. public class FastJsonTest {  
  7.     public static void main(String[] args){  
  8.         String jsonStr = "[{\"JACKIE_ZHANG\":\"张学友\"},{\"ANDY_LAU\":\"刘德华\"},{\"LIMING\":\"黎明\"},{\"Aaron_Kwok\":\"郭富城\"}]" ;  
  9.         //做5次测试  
  10.         for(int i=0,j=5;i<j;i++)  
  11.         {  
  12.             JSONArray jsonArray = JSONArray.parseArray(jsonStr);  
  13.   
  14.            for(int k=0;k<jsonArray.size();k++){  
  15.                System.out.print(jsonArray.get(k) + "\t");  
  16.            }  
  17.             System.out.println();//用来换行  
  18.         }  
  19.     }  
  20. }  

运行结果为:
  1. {"JACKIE_ZHANG":"张学友"} {"ANDY_LAU":"刘德华"}{"LIMING":"黎明"}{"Aaron_Kwok":"郭富城"}  
  2. {"JACKIE_ZHANG":"张学友"} {"ANDY_LAU":"刘德华"}{"LIMING":"黎明"}{"Aaron_Kwok":"郭富城"}  
  3. {"JACKIE_ZHANG":"张学友"} {"ANDY_LAU":"刘德华"}{"LIMING":"黎明"}{"Aaron_Kwok":"郭富城"}  
  4. {"JACKIE_ZHANG":"张学友"} {"ANDY_LAU":"刘德华"}{"LIMING":"黎明"}{"Aaron_Kwok":"郭富城"}  
  5. {"JACKIE_ZHANG":"张学友"} {"ANDY_LAU":"刘德华"}{"LIMING":"黎明"}{"Aaron_Kwok":"郭富城"}  


如果就想要定义为JSONObject,而不是JSONArray,可以选用其他JSON解析器,个人推荐使用google的gson,文档明显比fastjson好很多(从这里可以看出阿里巴巴和谷歌的差距):

  1. import com.google.gson.JsonElement;  
  2. import com.google.gson.JsonObject;  
  3. import com.google.gson.JsonParser;  
  4.   
  5. /** 
  6.  * Created by wangzhenfei on 14-4-15. 
  7.  */  
  8. public class FastJsonTest {  
  9.     public static void main(String[] args){  
  10.         String jsonStr = "{\"JACKIE_ZHANG\":\"张学友\",\"ANDY_LAU\":\"刘德华\",\"LIMING\":\"黎明\",\"Aaron_Kwok\":\"郭富城\"}" ;  
  11.         //做5次测试  
  12.         for(int i=0,j=5;i<j;i++)  
  13.         {  
  14.             JsonObject jsonObject = (JsonObject) new JsonParser().parse(jsonStr);  
  15.             for(java.util.Map.Entry<String,JsonElement> entry:jsonObject.entrySet()){  
  16.                 System.out.print(entry.getKey()+"-"+entry.getValue()+"\t");  
  17.             }  
  18.             System.out.println();//用来换行  
  19.         }  
  20.     }  
  21. }  

运行结果:
  1. JACKIE_ZHANG-"张学友"  ANDY_LAU-"刘德华"  LIMING-"黎明" Aaron_Kwok-"郭富城"      
  2. JACKIE_ZHANG-"张学友"  ANDY_LAU-"刘德华"  LIMING-"黎明" Aaron_Kwok-"郭富城"      
  3. JACKIE_ZHANG-"张学友"  ANDY_LAU-"刘德华"  LIMING-"黎明" Aaron_Kwok-"郭富城"      
  4. JACKIE_ZHANG-"张学友"  ANDY_LAU-"刘德华"  LIMING-"黎明" Aaron_Kwok-"郭富城"      
  5. JACKIE_ZHANG-"张学友"  ANDY_LAU-"刘德华"  LIMING-"黎明" Aaron_Kwok-"郭富城"      

posted @ 2015-02-27 18:52 朱杰兵 阅读(112) | 评论 (0)编辑 收藏

lamp(Web应用软件)

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

Apache是LAMP架构最核心的Web Server,开源、稳定、模块丰富是Apache的优势。但Apache的缺点是有些臃肿,内存和CPU开销大,性能上有损耗,不如一些轻量级的Web 服务器(例如nginx)高效,轻量级的Web服务器对于静态文件的响应能力来说远高于Apache服务器。

posted @ 2015-02-12 08:55 朱杰兵 阅读(87) | 评论 (0)编辑 收藏

很多登录功能上都有个“记住密码”的功能,其实无非就是对cookie的读取。

下面展示这个功能的代码,原作者已无法考究。。。。

测试方法:直接输入账号密码,提交后,刷新页面,再输入同样的账号,就可以显示

<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js COOKIE 记住帐号或密码</title>
<script type="text/javascript">
    window.onload=function onLoginLoaded() {
        if (isPostBack == "False") {
            GetLastUser();
        }
    }
     
    function GetLastUser() {
        var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";//GUID标识符
        var usr = GetCookie(id);
        if (usr != null) {
            document.getElementById('txtUserName').value = usr;
        } else {
            document.getElementById('txtUserName').value = "001";
        }
        GetPwdAndChk();
    }
    //点击登录时触发客户端事件
     
    function SetPwdAndChk() {
        //取用户名
        var usr = document.getElementById('txtUserName').value;
        alert(usr);
        //将最后一个用户信息写入到Cookie
        SetLastUser(usr);
        //如果记住密码选项被选中
        if (document.getElementById('chkRememberPwd').checked == true) {
            //取密码值
            var pwd = document.getElementById('txtPassword').value;
            alert(pwd);
            var expdate = new Date();
            expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000));
            //将用户名和密码写入到Cookie
            SetCookie(usr, pwd, expdate);
        } else {
            //如果没有选中记住密码,则立即过期
            ResetCookie();
        }
    }
     
    function SetLastUser(usr) {
        var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";
        var expdate = new Date();
        //当前时间加上两周的时间
        expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000));
        SetCookie(id, usr, expdate);
    }
    //用户名失去焦点时调用该方法
     
    function GetPwdAndChk() {
        var usr = document.getElementById('txtUserName').value;
        var pwd = GetCookie(usr);
        if (pwd != null) {
            document.getElementById('chkRememberPwd').checked = true;
            document.getElementById('txtPassword').value = pwd;
        } else {
            document.getElementById('chkRememberPwd').checked = false;
            document.getElementById('txtPassword').value = "";
        }
    }
    //取Cookie的值
     
    function GetCookie(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            //alert(j);
            if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }
    var isPostBack = "<%= IsPostBack %>";
     
    function getCookieVal(offset) {
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1) endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
    }
    //写入到Cookie
     
    function SetCookie(name, value, expires) {
        var argv = SetCookie.arguments;
        //本例中length = 3
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
    }
     
    function ResetCookie() {
        var usr = document.getElementById('txtUserName').value;
        var expdate = new Date();
        SetCookie(usr, null, expdate);
    }
</script>
</head>
<body>
<form id="form1">
  <div> 用户名:
    <input type="text" ID="txtUserName" onblur="GetPwdAndChk()">
    <input type="password" ID="txtPassword">
    密码:
    <input type="checkbox" ID="chkRememberPwd" />
    记住密码
    <input type="button" OnClick="SetPwdAndChk()" value="进入"/>
  </div>
</form>
</body>
</html>

posted @ 2015-01-31 13:48 朱杰兵 阅读(115) | 评论 (0)编辑 收藏

     摘要: settings.xml文件会指定仓库文件地址。  阅读全文

posted @ 2015-01-27 15:48 朱杰兵 阅读(97) | 评论 (0)编辑 收藏

仅列出标题
共14页: First 上一页 6 7 8 9 10 11 12 13 14 下一页