Thursday, 19 March 2015

An idea about create your own links anywhere, any message type

Here is my idea:

I wanna build a tool which is able to set your own links anywhere you want. It can be when you browse on BBC website, come across a special phrase, then you search on google, find the meaning for that, and you want to give it a remark so that review it next time when you see it.

Not just text from website, it can be any message type, like pictures, videos, even a song which type is mp3, you can still build a link for that.

So, this is something like bookmark, but it's much more power and useful than former one.

I hope anyone who is special interesting in my idea and able to develop this tool with me.

Moore Zhang

Saturday, 28 February 2015

HTTP Error 403.14 - Forbidden

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


Most likely causes:

  • A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

Things you can try:

  • If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
  • Enable directory browsing.
    1. Go to the IIS Express install directory.
    2. Run /section:system.webServer/directoryBrowse appcmd set config / enabled: true to enable Directory browsing at the Server Level.  
    3. Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse / enabled: true to enable Level Directory browsing at the site.  
  • Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

More Information:

This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.


Soluton: site.Master cannot be open, create a new form.aspx to use the master page!

Tuesday, 9 December 2014

Composite Primary Key using JPA and Hibernate

File: Customer.java


import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
public class Customer implements Serializable{
      
       @EmbeddedId
       @NotEmpty
       private CustomerId id;
       //Getter Setter for CustomerId
       public CustomerId getId() {
              return id;
       }
       public void setId(CustomerId id) {
              this.id = id;
       }
      
       private String customerBookItem;
       private String customerBookTime;
       //Getter Setter
       public String getCustomerBookItem() {
              return customerBookItem;
       }
       public void setCustomerBookItem(String customerBookItem) {
              this.customerBookItem = customerBookItem;
       }
       public String getCustomerBookTime() {
              return customerBookTime;
       }
       public void setCustomerBookTime(String customerBookTime) {
              this.customerBookTime = customerBookTime;
       }
      
      

}



File: CustomerId.java



import javax.persistence.Embeddable;
import java.io.Serializable;

@Embeddable
public class CustomerId implements Serializable{
      
       @NotEmpty
       private String customerBirthday;
       @NotEmpty
       private String customerName;
      
       //Constructor is necessary
       //default constructor
       public CustomerId() {
              super();
              // TODO Auto-generated constructor stub
       }
      
       //Constructor with attributes
       public CustomerId(String customerBirthday, String customerName) {
              super();
              this.customerBirthday = customerBirthday;
              this.customerName = customerName;
       }
      
       public String getCustomerBirthday() {
              return customerBirthday;
       }
       public void setCustomerBirthday(String customerBirthday) {
              this.customerBirthday = customerBirthday;
       }
       public String getCustomerName() {
              return customerName;
       }
       public void setCustomerName(String customerName) {
              this.customerName = customerName;
       }
      
}

Wednesday, 22 October 2014

多线程

进程与线程
多进程:在操作系统中能(同时)运行多个任务(程序)
多线程(multiple thread):在同一应用中有多个顺序流(同时)执行

线程lifecycle
线程类

//使用线程的方法一:继承Thread类
class FirstThread extends Thread(){
    //编写Run方法
    public void run(){
        for(int i = 0; i < 100; i++){
            System.out.println("");
        } 
    }
}

class Test{
    public static void main(String args[]){
        //生成线程类对象
        FirstThread ft = new FirstThread();
        //启动线程 ,使用start()方法,继承于Thread class
        //ft.run(); 单线程,不能这样写
        ft.start();//多线程
    }
}
Test class里有三个线程,将两个,一个是ft对象代表的线程,一个是Main()线程,(还有一个垃圾回收线程),CPU资源的分配是随机的。

//使用线程的方法二:接口Runnable
class runnableImp1 implements Runnable{
    public void run(){
        for(int i = 0; i < 100; i++){
        System.out.println("...");
        }
    }
}

class Test{
    public static void main(String args[]){
    //生成一个Runnable接口实现类的对象
    RunnableImpl ri = new RunnableImpl();
    //生成一个Thread对象,并将Runnable接口实现类的对象作为参数
    //传递给该Thread对象
    Thread t = new Thread();
    //通知Thread对象,执行start方法
    t.start();
    }
}

Java只支持单继承,推荐使用Runnable接口类

线程的简单控制方法
 - 中断线程
    Thread.sleep()
    Thread.yield()
 - 设置线程的优先级(1 - 10)
    getPriority()
    setPriority() by default, 优先级为5
优先级越大,执行的概率越大。

线程访问安全性
class MyThread implements Runnable{
    int i = 100;
    public void run(){
        while(true){
            //同步代码块
            synchroized(this){
                System.out.println(Thread.currentThread().getName() + i);
                i--;
                Thread.yield();
                if(i < 0){
                    break;
                }
            }
        }
    }
}

class Test{
    public static void main(String args[]){
        MyThread myThread = new MyThread();
        //生成两个Thread对象,共用同一个线程体
        Thread t1 = new Thread(myThread);
        Thread t2 = new Thread(myThread);
        //每一个线程都有名字,可以通过Thread对象setName()设置线程名字,也可以使用getName()获取线程的名子。
        t1.setName("线程a");
        t2.setName("线程b");
 
        t1.start();
        t2.start();
    }
}

多线程访问同一份资源,会出现多线程错误。解决方法:使用同步锁synchronized(this)

深入synchronized关键字
同步代码块(锁住对象)与同步方法作用类似,区别是同步代码块直接指定对象,同步方法也是指this。

Monday, 20 October 2014

DCI - Distributed Computing Infrastructure

Characteristics of application
Applications are:
 - Workflow solutions
 - Enterprise solutions
 - Customer Relationship solution

Customers => Sever => Database

Traditional Client / Server Environment(linked by a network using protocol such as Microsoft Network)
Strength(Application run on Local Area Environment)
 - high network speed as compared to over the Internet
 - easy of ensuring security
 - consistent UI using Windows
 - well controlled/consistent client platform
 - good control of starting and ending of application (session management)
Weakness
  - Specific client software required on each Individual terminal(difficult in implementation and maintenance)

Web-based Client / Server Environment(linked by a network using Internet protocol - TCP/IP)
Strength
 - application running on standard Intranet/Internet protocol(TCP/IP)
 - easy implementation and maintenance
 - consistent UI on different platforms(browser UI)
Weakness
 - lower network speed as compared to LAN
 - difficult to ensure security(over public switching telephone network)

Internet Protocol
TCP: Transmission Control Protocol
IP: Internet Protocol
HTTP: HyperText Transport Protocol
HTTPS: HyperText Transport Protocol Secure
Cookie Format(Write onto client machine):
Set-Cookie: NAME=VALUE; expired=DATE; path=PATH; domain=DOMAIN_NAME; secure
 - expires syntax must be "Weekday, dd-mmm-yyyy hh:mm:ss GMT"
 - domain must have at least 2 dots(3 dots for domains outside USA)
 - path refers to a URL path within the Web server
 - secure, if present, limits transmission to secure server

Internet 
Plug-ins: are programs modules loaded by the browser to handle specific file-formats.
Internet application and Intranet application

Empowering the Client
Scripting (no compilation needed)
          JavaScript (Netscape) - supported by almost every browsers, such as IE, Netscape, etc
          VBScript (Microsystem)
Components (compilation needed) - IE
          Java Applet (Sun Microsystem)
          ActiveX Control (Microsoft)


Wednesday, 15 October 2014

Using LINQ or Lambda Expressions to Entities - Entity Framework Query Options

LINQ to Entities
a. Create new entityframework(EF) called DefestyEntity;
b. Tables generated by EF are Customers, Orders, and so on;
c. Queries must be well defined at compile time;

Codes:
DafestyEntity ctx = new DafestyEntity();

var query = from x in ctx.Orders
                    where x.Customer.CustomerID == "Tom"
                    select x;
foreach (var x in query)
    Console.WriteLine("{0} {1}", x.OrderID, x.OrderDate);

LINQ Key Words
- from
  Specifies a data source and a range variable (similar to an iteration variable).
- where
  Filters source elements based on one or more Boolean expressions separated by logical AND and OR operators(&& or ||)
- select
  Specifies the type and shape that the elements in the returned sequence will have when the query is executed.
- group
  Groups query results according to a specified key value.
- into
  Provides an identifier that can serve as a reference to the results of a join, group or select clause.
- order by
  Sorts query results in ascending or descending order based on the default comparer for the element type.
- join
  Joins two data sources based on an equality comparison between two specified matching criteria.


Lambda Expressions
a. A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

Codes:
ctx.Orders.Where(x => x.CustomerID =="Tom");