加style="cursor:hand" ,firefox無效。
posted @
2008-03-16 12:56 流浪汗 閱讀(4150) |
評論 (2) |
編輯 收藏
收集于網絡,自已小改動下。
有DrawImage(ImgD, width, height) 調整圖像比例的javascript函數。
<script language="javascript">
<!--
var flag=false;
function DrawImage(ImgD, width, height){
var image=new Image();
var iwidth = width;
var iheight = height;
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+""+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+""+image.height;
}
}
}
//-->
</script>
<style type="text/css">
.pic_size {border:1px solid #CCCCCC;width:240px;height:200px;margin-top:5px;background:#FFF;}
</style>
<div class="pic_size"><table width="100%" height="100%"><tr><td style="text-align: center;vertical-align: middle;"><img src="my.jpg" onload = "DrawImage(this,240,200)"></td></tr></table></div>
posted @
2008-03-16 12:43 流浪汗 閱讀(373) |
評論 (0) |
編輯 收藏
在HTML內頭部加以下內容。
<link rel="shortcut icon" href="/images/my.ico" type="image/x-icon" />
posted @
2008-03-16 12:32 流浪汗 閱讀(343) |
評論 (0) |
編輯 收藏
以前想用循環來System.in (或是其它輸入方式老是達不預想的效果,第一次輸入后回車,不會接收下一次用戶的輸入)。后來才發現readline() != null才能達到效果。
package net.blogjava.chenlb;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 重復接收用戶輸入一行命令
* @author chenlb 2008-3-11 下午09:24:50
*/
public class UserInput {
public static void main(String[] args) throws IOException {
System.out.println("說明: 輸入QUIT退出");
System.out.print("\ninput>");
String inputStr = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while((inputStr = br.readLine()) != null) {
if(inputStr.equals("QUIT")) {
System.exit(0);
}
System.out.println("你輸入的是: "+inputStr); //處理你的邏輯
System.out.print("\ninput>");
}
}
}
posted @
2008-03-11 21:49 流浪汗 閱讀(976) |
評論 (0) |
編輯 收藏
最近看下Lucene的東西,把它寫下來可以看下。Lucene結構和工作原理我就不說了,網上好多。
我的環境是Lucene2.0
寫一個簡單使用Lucene的示例。此類首創建索引,然后顯示索引文檔的情況,最后搜索(只在content找,和在title或content里找)。
package net.blogjava.chenlb.lucene;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
/**
* Lucene簡單使用
* @author chenlb 2008-3-8 下午11:42:55
*/
public class LuceneUse {
public static void main(String[] args) throws Exception {
LuceneUse liu = new LuceneUse();
//索引
IndexWriter iw = new IndexWriter("index", new StandardAnalyzer(), true);
//添加要索引的Lucene文檔
Document doc = liu.createDoc("Lucene創建索引示例", "chenlb", "2008-03-08", "Lucene索引的內容在這里,這些內容不被存儲.");
iw.addDocument(doc);
doc = liu.createDoc("文檔2", "bin", "2007-10-03", "這是索引的另一個文檔");
iw.addDocument(doc);
doc = liu.createDoc("學習內容", "chenlb", "2008-3-3", "要努力奮斗,祝網友們天天快樂");
iw.addDocument(doc);
iw.optimize(); //優化
iw.close();
//讀
System.out.println("===========索引文檔內容=============");
IndexReader reader = IndexReader.open("index");
for(int i=0; i<reader.numDocs(); i++) {
Document d = reader.document(i);
liu.printDoc(d);
}
System.out.println("===========以下是單域查找'天天'結果============");
//單域搜索
IndexSearcher searcher = new IndexSearcher("index");
QueryParser parser = new QueryParser("content", new StandardAnalyzer());
Query q = parser.parse("天天");
long start = System.currentTimeMillis();
Hits hits = searcher.search(q);
long end = System.currentTimeMillis();
for(int i=0; i<hits.length(); i++) {
liu.printDoc(hits.doc(i));
}
System.out.println("共找到: "+hits.length()+" 個文檔,花了:"+(end-start)+"ms");
//多域搜索
System.out.println("===========以下多域是查找'內容'結果============");
//從title或content找
q = MultiFieldQueryParser.parse("內容", new String[] {"title", "content"}, new BooleanClause.Occur[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
start = System.currentTimeMillis();
hits = searcher.search(q);
end = System.currentTimeMillis();
for(int i=0; i<hits.length(); i++) {
liu.printDoc(hits.doc(i));
}
System.out.println("共找到: "+hits.length()+" 個文檔,花了:"+(end-start)+"ms");
}
/**
* 顯示文檔內容
*/
private void printDoc(Document d) {
System.out.println("標題: "+d.get("title")+", 作者: "+d.get("author")+", 日期: "+d.get("date")+", 內容: "+d.get("content"));
}
/**
* 創建一個Lucene文檔
*/
private Document createDoc(String title, String author, String date, String content) {
Document doc = new Document();
doc.add(new Field("title", title, Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("author", author, Field.Store.YES, Field.Index.NO));
doc.add(new Field("date", date, Field.Store.YES, Field.Index.NO));
doc.add(new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED));
return doc;
}
}
posted @
2008-03-09 00:47 流浪汗 閱讀(972) |
評論 (0) |
編輯 收藏
這幾天想用Java讀富文檔。用javax.swing.text和javax.swing.text.rtf包中的類讀RTF文檔時出現中文亂碼問題(出現?號)。
幸好找到
ANGEL SKY 的博客。用ISO8859_1編碼轉換。
代碼片斷:
String bodyText = null;
DefaultStyledDocument styledDoc = new DefaultStyledDocument(); //javax.swing.text.Document的一個實例
try {
InputStream is = new FileInputStream(new File("data/java.swing.text讀RTF文檔測試.rtf"));
new RTFEditorKit().read(is, styledDoc, 0);
bodyText = new String(styledDoc.getText(0, styledDoc.getLength()).getBytes("ISO8859_1")); //提取文本
} catch (IOException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
} catch (BadLocationException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
}
System.out.println(bodyText);
posted @
2008-02-01 17:05 流浪汗 閱讀(2279) |
評論 (0) |
編輯 收藏
這學期,應聘的時候有一些是線程相關的,雖然自己對線程編程有點概念,但沒有寫過經典的例子。放假了有點時候,就想寫多線程的例子。
筆試的題目類似地:一個生產者一次生產10個,滿了后通知消費者,然后等待。一個消費者產品有滿了就消費。到空時通知生產者,然后等待。
那時對等待/通知機制沒怎么寫過,那次筆試應該寫的大概對(想法對),但寫的wait()和notifyAll()的位置不對。現在有時間就寫了這個例子。
描述:生產者一次生產N個產品,池中達到M就等待,通知等待的消費者。消費者有產品就消費,到沒有時就通知生產者,然后等待。
1.生產者:
package net.blogjava.chenlb.multithreaded;
import java.util.List;
/**
* @author chenlb
*
* 生產者.<br/>
* 默認產品池大小M=20,產品梯階大小N=5.在生產過程中,池的大小會超過20,但池中最大應該是M+N-1.
*/
public class Producer implements Runnable {
/**
* 池默認大小
*/
public static final int DEFALUT_SIZE = 20;
/**
* 默認一次生產的數量
*/
public static final int DEFALUT_STEP_SIZE = 5;
private static int PRODUCER_ID = 0; //生產者號
private List<Product> pool = null;
private int size = DEFALUT_SIZE;
private int stepSize = DEFALUT_STEP_SIZE;
private String name = "Producer_"+(++PRODUCER_ID); //生產者名
private boolean isRun = true;
/**
* 默認產品池大小20, 默認產品增長梯階大小5
*/
public Producer(List<Product> pool) {
this.pool = pool;
}
/**
* @param pool
* @param size 池大小
*/
public Producer(List<Product> pool, int size) {
this.pool = pool;
this.size = size;
}
/**
* @param pool
* @param size 池大小
* @param stepSize 一次生產多少
*/
public Producer(List<Product> pool, int size, int stepSize) {
this.pool = pool;
this.size = size;
this.stepSize = stepSize;
}
public void run() {
// TODO 生產者線程
//int pi = 0;
while(isRun) {//&& pi<10
//pi++;
synchronized (pool) { //同步產品池
if(pool.size() >= size) {
try {
System.out.println(name+" 等待!");
pool.wait(); //同步什么就等待什么,否則拋出java.lang.IllegalMonitorStateException
} catch (InterruptedException e) {
isRun = false;
System.out.println(name+" thread interrupt!");
}
} else {
for(int i=0; i<stepSize; i++) { //一次生產stepSize個產品
pool.add(product()); //生產產品
}
System.out.println("產品池中有: "+pool.size());
pool.notifyAll(); //通知等待的線程(主要用來通知消費者, 但生產者線程也會通知到)
}
}
try {
System.out.println(name+" 休息1秒!");
Thread.sleep(1000); //調試用
} catch (InterruptedException e) {
System.out.println(name+" sleep 1s thread interrupt");
}
}
System.out.println(name+" end! pool size: "+pool.size());
}
private static int P_ID = 0;
/**
* 生產產品
* @return 產品
*/
private Product product() {
String name = "product_"+(++P_ID);
System.out.println(this.name+" 生產了: "+name);
return new Production(name);
}
}
2.消費者:
package net.blogjava.chenlb.multithreaded;
import java.util.List;
/**
* @author chenlb
*
* 消費者
*/
public class Consumer implements Runnable {
private static int C_ID = 0; //消費者ID
private List<Product> pool = null;
private String name = "Consumer_"+(++C_ID);
private boolean isRun = true;
public Consumer(List<Product> pool) {
this.pool = pool;
}
public void run() {
// TODO 消費者線程
//int pi = 0;
while(isRun) {//&& pi<10
//pi++;
synchronized (pool) {
if(pool.size() < 1) {
try {
System.out.println(name+" 等待!");
pool.notifyAll(); //通知線程(主要是生產者,但也會通知到生產者線程)
pool.wait();
} catch (InterruptedException e) {
isRun = false;
System.out.println(name+" thread interrupt!");
}
} else {
Product p = pool.remove(0); //消費
printProduct(p);
}
}
try {
Thread.sleep(1000); //調試用
} catch (InterruptedException e) {
System.out.println(name+" sleep 1s thread interrupt");
}
}
System.out.println(name+" end! pool size: "+pool.size());
}
private void printProduct(Product p) {
System.out.println(name+" 消費了: "+p.getName());
}
}
3.Demo
package net.blogjava.chenlb.multithreaded;
import java.util.LinkedList;
import java.util.List;
/**
* @author chenlb
*
*/
public class Sale {
public static void main(String[] args) {
//鏈表產品池
List<Product> pool = new LinkedList<Product>();
//兩個生產者
Producer p1 = new Producer(pool);
Producer p2 = new Producer(pool);
Thread tp1 = new Thread(p1);
Thread tp2 = new Thread(p2);
tp1.start();
tp2.start();
//兩個消費者
Consumer c1 = new Consumer(pool);
Consumer c2 = new Consumer(pool);
Thread tc1 = new Thread(c1);
Thread tc2 = new Thread(c2);
tc1.start();
tc2.start();
}
}
注意:等待時候要用pool.wait()因為同步的是pool。否則會拋出java.lang.IllegalMonitorStateException
^_^
代碼下載
posted @
2008-01-24 11:36 流浪汗 閱讀(541) |
評論 (0) |
編輯 收藏
1.聚合關系也稱"has-a"關系,組合關系也稱"contains-a"關系
2.聚合關系表示事物的整體/部分關系的較弱情況,組合關系表示事物的整體/部分關系的較強的情況.
3.在聚合關系中,代表部分事物的可以屬于多個聚合對象,可以為多個聚合對象共享,而且可以隨時改變它所從屬的聚合對象.代表部分事物的對象與代表聚合事物對象的生存期無關,一旦刪除了它的一個聚合對象,不一定也就隨即刪除代表部分事物的對象.在組合關系中,代表整體事物的對象負責創建和刪除代表部分事物的對象,代表部分事物只屬于一個組合對象.一旦刪除了組合對象,也就隨即刪除了相應的代表部分事物的對象.
posted @
2008-01-15 22:02 流浪汗 閱讀(2647) |
評論 (0) |
編輯 收藏
oracle 用戶SYS 和 SYSTEM的默認口令:TIGER
posted @
2008-01-03 15:10 流浪汗 閱讀(1496) |
評論 (0) |
編輯 收藏
1.什么是pv
PV(page view),即頁面瀏覽量,或點擊量;通常是衡量一個網絡新聞頻道或網站甚至一條網絡新聞的主要指標。
高手對pv的解釋是,一個訪問者在24小時(0點到24點)內到底看了你網站幾個頁面。這里需要強調:同一個人瀏覽你網站同一個頁面,不重復計算pv量,點100次也算1次。說白了,pv就是一個訪問者打開了你的幾個頁面。
PV之于網站,就像收視率之于電視,從某種程度上已成為投資者衡量商業網站表現的最重要尺度。
pv的計算:當一個訪問著訪問的時候,記錄他所訪問的頁面和對應的IP,然后確定這個IP今天訪問了這個頁面沒有。如果你的網站到了23點,單純IP有60萬條的話,每個訪問者平均訪問了3個頁面,那么pv表的記錄就要有180萬條。
有一個可以隨時查看PV流量以及你的網站世界排名的工具alexa工具條,安裝吧!網編們一定要安裝這個。
2.什么是uv
uv(unique visitor),指訪問某個站點或點擊某條新聞的不同IP地址的人數。
在同一天內,uv只記錄第一次進入網站的具有獨立IP的訪問者,在同一天內再次訪問該網站則不計數。獨立IP訪問者提供了一定時間內不同觀眾數量的統計指標,而沒有反應出網站的全面活動。
3.什么是PR值
PR值,即PageRank,網頁的級別技術。取自Google的創始人Larry Page,它是Google排名運算法則(排名公式)的一部分,用來標識網頁的等級/重要性。級別從1到10級,10級為滿分。PR值越高說明該網頁越受歡迎(越重要)。
例如:一個PR值為1的網站表明這個網站不太具有流行度,而PR值為7到10則表明這個網站非常受歡迎(或者說極其重要)。
我們可以這樣說:一個網站的外部鏈接數越多其PR值就越高;外部鏈接站點的級別越高(假如Macromedia的網站鏈到你的網站上),網站的PR值就越高。例如:如果ABC.COM網站上有一個XYZ.COM網站的鏈接,那為ABC.COM網站必須提供一些較好的網站內容,從而Google會把來自XYZ.COM的鏈接作為它對ABC.COM網站投的一票。
你可以下載和安裝Google工具條來檢查你的網站級別(PR值)。
詳細看: http://www.skynuo.com/faq_qc7.htm
posted @
2007-12-31 13:51 流浪汗 閱讀(378) |
評論 (0) |
編輯 收藏