Java Servlet International Character Encoding UTF-8 with Hibernate and MySQL 中文显示

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Add following script to your hibernate.cfg.xml file. “useUnicode=true&characterEncoding=utf-8”

 <property name="hibernate.connection.url">jdbc:mysql://localhost/yourschema?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8</property>

如果你使用Java Servlet, Mysql和Hibernate, 为了正常显示及存储中文, 可以加入以上脚本

如果显示仍然有问题, 可以尝试使用:

String str="中文测试"; new String(str.getBytes("iso-8859-1"), "utf-8"); 

Read More

highstock example

Setting Individual Point color in Series for Highstock API

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

I was working on Highstock, I tried to set a color to a specific point in “data” in Highstock, like in the example,the example is implemented using Highchart API,but I couldn’t get it to work with Highstock API, no matter how I set the color, it doesn’t show on the graph.

Thanks for stackoverflow, someone helped me.


It’s important to put marker enable in the plotOptions, otherwise it won’t work.

 plotOptions: {
        series: {
            marker: {
                enabled: true    
            }
        }
    },
$(function () {
    var seriesSetting=[{name:"aaa",
            data: [{x: 1343862840000,y: 4.447361},{x:1343863200000,y:5,marker:{fillColor:'red'}},{x:1343873200000,y:8}]
        }];
    var chart = new Highcharts.StockChart({
        useUTC:false,
                showLoading:"loading",
                chart:{
                    renderTo:'container',
                    type:'spline',
                    events:{
                        load: function(chart) {
                            this.setTitle(null, {
                                text: 'Built chart at '+ (new Date() - start) +'ms'
                            });
                        }

                    }
                },
                legend:{
                    enabled:true,
                    showInLegend:true,
                    layout:'vertical',
                    align:'right',
                    verticalAlign:'top',
                    x:-10,
                    y:100,
                    borderWidth:0
                },
                rangeSelector:{
                    enabled:false
                },         
                xAxis:{
                    title:{
                        text:'time'
                    },

                    //    tickLength:100,
                    ordinal: false,
                    type:'datetime',
                },
                tooltip:{
                    shared:false,
                    shadow:false,
                    style:{
                        //  color:'#333333',
                        fontSize:'9pt',
                        padding:'5px'
                    }
                },
                yAxis:{
                    title:"value"
                },
                plotOptions:{
                    series:{turboThreshold: 99999,  marker: {
                           enabled: true
                       }
                    }},
                series:seriesSetting
    });
});

Read More

Get URL request parameter with jQuery (Javascript)

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Here is an example of how to get URL request parameters in Javascript (Jquery)

http://www.leonli.co.uk?search=parameters
        function getURLParameter(name) {
            return decodeURI(
                    (RegExp(name + '=' + '(.+?)(&amp;|$)').exec(location.search)||[,null])[1]
            );
        }
 var parameter=url.getURLParameter("search"); 

Read More

Install and Configure FTP(Vsftpd) service in CentOS/Linux

Q. How do I configure and install an FTP server in CentOS / RHEL 5 / Fedora Linux server?
A. CentOS / RHEL server comes with vsftpd which is the Very Secure File Transfer Protocol (FTP) daemon. The server can be launched via a xinetd or as standalone mode, in which case vsftpd itself will listen on the network port 21.

[root@leonli.co.uk ~]# yum -y install vsftpd
[root@leonli.co.uk ~]# vi /etc/vsftpd/vsftpd.conf
# line 12: no anonymous
anonymous_enable=NO
# line 80,81: uncomment ( allow ascii mode )
ascii_upload_enable=YES
ascii_download_enable=YES
# line 95, 96: uncomment ( enable chroot )
chroot_local_user=YES
chroot_list_enable=YES
# line 98: uncomment ( specify chroot list )
chroot_list_file=/etc/vsftpd/chroot_list
# line 104: uncomment
ls_recurse_enable=YES
# add at the last line 
# specify root directory ( if don't specify, users' home directory become FTP home directory)
local_root=public_html
# use localtime
use_localtime=YES
[root@leonli.co.uk ~]# vi /etc/vsftpd/chroot_list
# add users you allow to move over their home directory
cent
[root@leonli.co.uk ~]# /etc/rc.d/init.d/vsftpd start 
Starting vsftpd for vsftpd: [  OK  ]
[root@leonli.co.uk ~]# chkconfig vsftpd on

Read More

vi commands cheat sheet/command list

Cursor movement

  • h – move left
  • j – move down
  • k – move up
  • l – move right
  • w – jump by start of words (punctuation considered words)
  • W – jump by words (spaces separate words)
  • e – jump to end of words (punctuation considered words)
  • E – jump to end of words (no punctuation)
  • b – jump backward by words (punctuation considered words)
  • B – jump backward by words (no punctuation)
  • 0 – (zero) start of line
  • ^ – first non-blank character of line
  • $ – end of line
  • G – Go To command (prefix with number – 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode – Inserting/Appending text

  • i – start insert mode at cursor
  • I – insert at the beginning of the line
  • a – append after the cursor
  • A – append at the end of the line
  • o – open (append) blank line below current line (no need to press return)
  • O – open blank line above current line
  • ea – append at end of word
  • Esc – exit insert mode

Editing

  • r – replace a single character (does not use insert mode)
  • J – join line below to the current one
  • cc – change (replace) an entire line
  • cw – change (replace) to the end of word
  • c$ – change (replace) to the end of line
  • s – delete character at cursor and subsitute text
  • S – delete line at cursor and substitute text (same as cc)
  • xp – transpose two letters (delete and paste, technically)
  • u – undo
  • . – repeat last command

Marking text (visual mode)

  • v – start visual mode, mark lines, then do command (such as y-yank)
  • V – start Linewise visual mode
  • o – move to other end of marked area
  • Ctrl+v – start visual block mode
  • O – move to Other corner of block
  • aw – mark a word
  • ab – a () block (with braces)
  • aB – a {} block (with brackets)
  • ib – inner () block
  • iB – inner {} block
  • Esc – exit visual mode

Visual commands

  • > – shift right
  • < – shift left
  • y – yank (copy) marked text
  • d – delete marked text
  • ~ – switch case

Cut and Paste

  • yy – yank (copy) a line
  • 2yy – yank 2 lines
  • yw – yank word
  • y$ – yank to end of line
  • p – put (paste) the clipboard after cursor
  • P – put (paste) before cursor
  • dd – delete (cut) a line
  • dw – delete (cut) the current word
  • x – delete (cut) current character

Exiting

  • :w – write (save) the file, but don’t exit
  • :wq – write (save) and quit
  • :q – quit (fails if anything has changed)
  • :q! – quit and throw away changes

Search/Replace

  • /pattern – search for pattern
  • ?pattern – search backward for pattern
  • n – repeat search in same direction
  • N – repeat search in opposite direction
  • :%s/old/new/g – replace all old with new throughout file
  • :%s/old/new/gc – replace all old with new throughout file with confirmations

Working with multiple files

  • :e filename – Edit a file in a new buffer
  • :bnext (or :bn) – go to next buffer
  • :bprev (of :bp) – go to previous buffer
  • :bd – delete a buffer (close a file)
  • :sp filename – Open a file in a new buffer and split window
  • ctrl+ws – Split windows
  • ctrl+ww – switch between windows
  • ctrl+wq – Quit a window
  • ctrl+wv – Split windows vertically

Reference:
http://www.worldtimzone.com/res/vi.html

Read More

Vim Commands Cheat Sheet/Command List

How to Exit

:q[uit] Quit Vim. This fails when changes have been made.
:q[uit]! Quit without writing.
:cq[uit] Quit always, without writing.
:wq Write the current file and exit.
:wq! Write the current file and exit always.
:wq {file} Write to {file}. Exit if not editing the last
:wq! {file} Write to {file} and exit always.
:[range]wq[!] [file] Same as above, but only write the lines in [range].
ZZ Write current file, if modified, and exit.
ZQ Quit current file and exit (same as “:q!”).

 


Editing a File

:e[dit] Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim.
:e[dit]! Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again.
:e[dit] {file} Edit {file}.
:e[dit]! {file} Edit {file} always. Discard any changes to the current buffer.
gf Edit the file whose name is under or after the cursor. Mnemonic: “goto file”.

 


Inserting Text

a Append text after the cursor [count] times.
A Append text at the end of the line [count] times.
i Insert text before the cursor [count] times.
I Insert text before the first non-blank in the line [count] times.
gI Insert text in column 1 [count] times.
o Begin a new line below the cursor and insert text, repeat [count] times.
O Begin a new line above the cursor and insert text, repeat [count] times.

 


Inserting a file

:r[ead] [name] Insert the file [name] below the cursor.
:r[ead] !{cmd} Execute {cmd} and insert its standard output below the cursor.

 


Deleting Text

<Del> or
x
Delete [count] characters under and after the cursor
X Delete [count] characters before the cursor
d{motion} Delete text that {motion} moves over
dd Delete [count] lines
D Delete the characters under the cursor until the end of the line
{Visual}x or
{Visual}d
Delete the highlighted text (for {Visual} see Selecting Text).
{Visual}CTRL-H or
{Visual}
When in Select mode: Delete the highlighted text
{Visual}X or
{Visual}D
Delete the highlighted lines
:[range]d[elete] Delete [range] lines (default: current line)
:[range]d[elete] {count} Delete {count} lines, starting with [range]

(more…)

Read More

How to use Gson convert Java object to Json String (serialize POJO) with root value included

If you are using Gson library (google-gsonA Java library to convert JSON to Java objects and vice-versa) and you want to serialize POJO with root value included like the following illustrated code for serializing XML.

@XmlRootElement
class Person implements Serializable {
    private String firstname;
    private String lastname;
    public Person() {
    firstname="firstname";
    lastname="lastname";
   }
}
......

It’s very simple, here is an example to do it with Gson:

    Gson gson = new Gson();
    JsonElement je = gson.toJsonTree(new Person());
    JsonObject jo = new JsonObject();
    jo.add("PersonRoot",je);

Read More