
2011年2月26日
使用w3m上網(wǎng)方法:
第一步,需要安裝一個(gè)名為w3m的軟件工具,打開終端,輸入如下命令
sudo apt-get install w3m w3m-img -y
第二步,安裝好w3m之后,在終端里面啟動(dòng)w3m,打開一個(gè)網(wǎng)址,比如w3m www.baidu.com 。現(xiàn)在是不是看到了只有在瀏覽器下面才能看到的百度首頁呢?
如果您的終端不顯示中文請。安裝zhcon。安裝命令:
sudo apt-get install zhcon -y
好了,下面給出w3m的相關(guān)幫助文件。
與vim常用命令vim常用命令集相似,h,j,k,l 可以分別用來做移動(dòng)鍵,分別是左,下,上,右。如果你熟習(xí)vim操作的話這會(huì)是很方便的功能。 < 和 > 用來左右滾屏。
按q就會(huì)提示你退出!
在需要輸入的文本框內(nèi)按回車,下面就會(huì)出現(xiàn)TEXT: ,這時(shí)你可以輸入你要搜索的文字。再按回車就是返回給文本框。這時(shí)再把光標(biāo)移到”百度搜索”的那個(gè)按鍵,回車,就可以開始搜索了!
使用 U 來重新輸入需要打開的網(wǎng)址。
B 返回前一個(gè)頁面。
多標(biāo)簽操作!
可以使用 T 按鍵來打開一個(gè)新標(biāo)簽。
在多個(gè)標(biāo)簽內(nèi)切換呢? 使用 { 和 }就可以了!
使用 ESC-t 的話會(huì)打開標(biāo)簽的菜單讓你選擇,功能類似系統(tǒng)中的alt-tab功能。
C-q用于關(guān)于當(dāng)前標(biāo)簽頁。
書簽
C-a 添加書簽
C-b 查看書簽
查找
/ 向后查找當(dāng)前頁面
? 向前查找當(dāng)前頁面
n 查找下一個(gè)已查找過的關(guān)鍵字
N 向前查找已查找過的關(guān)鍵字
幫助
H 以上的選項(xiàng)在這里都可以看到!
posted @
2011-09-23 17:00 Soap MacTavish 閱讀(10367) |
評論 (1) |
編輯 收藏
在使用SWT構(gòu)建應(yīng)用程序時(shí),理解系統(tǒng)底層讀取和調(diào)度平臺(tái)GUI事件的線程模型是非常重要的,UI線程的實(shí)現(xiàn)方式會(huì)影響到在應(yīng)用程序中使用 Java 線程時(shí)必須遵守的規(guī)則。
本地事件調(diào)度
對于任何的GUI應(yīng)用程序,不管所使用的是哪一種編程語言和UI工具包,背后的運(yùn)行機(jī)制都是操作系統(tǒng)探測GUI事件并把它們放到應(yīng)用程序的事件隊(duì)列中去。這種機(jī)制在不同的操作系統(tǒng)平臺(tái)中大同小異。當(dāng)用戶點(diǎn)擊鼠標(biāo)、鍵入字符、或者使窗口獲得焦點(diǎn),操作系統(tǒng)就會(huì)生成應(yīng)用程序的GUI事件,例如鼠標(biāo)點(diǎn)擊、鍵盤輸入、或窗口重繪事件。操作系統(tǒng)決定哪一個(gè)窗口和應(yīng)用程序應(yīng)該接收用戶觸發(fā)的每一個(gè)事件并把它放入應(yīng)用程序的事件隊(duì)列中。
任何基于窗口的GUI應(yīng)用程序的底層實(shí)現(xiàn)結(jié)構(gòu)都是一個(gè)事件循環(huán)(event loop),應(yīng)用程序初始化并運(yùn)行一個(gè)循環(huán)(loop),用于從事件隊(duì)列中讀取GUI事件,并作出相應(yīng)的反應(yīng)。處理事件的工作必須迅速完成,以保證GUI應(yīng)用程序能夠?qū)τ脩糇鞒隹焖俜磻?yīng)。
UI事件觸發(fā)的耗時(shí)較長的操作應(yīng)該在一個(gè)單獨(dú)的線程中執(zhí)行,這樣才能讓事件循環(huán)主線程能夠快速返回,獲取應(yīng)用程序事件隊(duì)列中的下一個(gè)事件。但是,在非UI線程中訪問圖形界面部件和平臺(tái)API 必須通過鎖和串行化的機(jī)制(locking and serialization)來實(shí)現(xiàn)。違反這個(gè)規(guī)則的應(yīng)用程序會(huì)引起系統(tǒng)調(diào)用失敗,更嚴(yán)重的是鎖住整個(gè)GUI系統(tǒng),使GUI失去反應(yīng)。
SWT UI 線程
SWT 遵循系統(tǒng)平臺(tái)所直接支持的這種線程模型,應(yīng)用程序在它的主線程中運(yùn)行事件循環(huán)(event loop),并在主線程中直接調(diào)度線程。UI線程就是Display 對象被創(chuàng)建的線程,所有其他的圖形部件都必須在這個(gè)UI線程中創(chuàng)建。
既然所有的處理事件的代碼是在應(yīng)用程序的UI線程中觸發(fā)的,那么處理事件的程序代碼就能夠不需要任何特殊方法自由訪問和調(diào)用圖形部件。不過,在處理長耗時(shí)的事件操作時(shí),需要使用多線程來實(shí)現(xiàn)應(yīng)用程序的功能。
注:在非UI線程中調(diào)用任何必須在UI線程調(diào)用的程序,SWT將會(huì)觸發(fā)一個(gè) SWTException 異常。
SWT 應(yīng)用程序的主線程,包括事件循環(huán),其代碼結(jié)構(gòu)如下:
- public static void main (String [] args) {
- Display display = new Display ();
- Shell shell = new Shell (display);
- shell.open ();
-
-
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ())
- display.sleep ();
- }
- display.dispose ();
- }
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.open ();
// start the event loop. We stop when the user has done
// something to dispose our window.
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}
創(chuàng)建圖形部件和打開shell 窗口之后,程序讀取和分發(fā)來自操作系統(tǒng)事件隊(duì)列的事件,直到shell 窗口被銷毀。如果在隊(duì)列中不存在有效事件,display 進(jìn)入睡眠狀態(tài),把運(yùn)行機(jī)會(huì)交給其他程序。
SWT 提供了在后臺(tái)主線程中調(diào)用圖形部件代碼的訪問方法。
運(yùn)行非UI線程
在非UI 線程中不能直接調(diào)用UI 代碼,必須提供一個(gè) Runnable對象,在Runable中調(diào)用UI代碼。Display 類中的syncExec(Runnable) 和 asyncExec(Runnable) 方法用于在事件循環(huán)運(yùn)行期間,在UI 線程中運(yùn)行這些Runnable對象。
- syncExec(Runnable) 當(dāng)非UI 線程中的程序代碼依賴于UI 代碼的返回值,或者為了確保在返回到主線程之前Runnable 必須執(zhí)行完成時(shí),應(yīng)該使用這個(gè)方法。SWT 將會(huì)阻塞調(diào)用線程,直到在應(yīng)用程序的UI 線程中運(yùn)行的這個(gè)Runnable運(yùn)行結(jié)束為止。例如,一個(gè)后臺(tái)線程需要基于一個(gè)窗口的當(dāng)前尺寸進(jìn)行某種計(jì)算,就會(huì)需要同步地運(yùn)行獲取窗口尺寸的代碼,然后繼續(xù)其后面的計(jì)算。
- asyncExec(Runnable) 當(dāng)程序需要執(zhí)行一些UI 操作,但在繼續(xù)執(zhí)行之前不依賴這些操作必須完成的時(shí)候,應(yīng)該使用這個(gè)方法。例如,后臺(tái)主線程更新進(jìn)度條,或者重繪一個(gè)窗口,它可以異步地發(fā)出更新或重繪的請求,并接著繼續(xù)后面的處理,在這種情況下,后臺(tái)主線線程的運(yùn)行時(shí)間和Runnable的運(yùn)行沒有必然的關(guān)系。
下面的代碼片段演示了使用這兩個(gè)方法的方式:
-
- ...
-
-
- display.asyncExec (new Runnable () {
- public void run () {
- if (!myWindow.isDisposed())
- myWindow.redraw ();
- }
- });
-
- ...
// do time-intensive computations
...
// now update the UI. We don't depend on the result,
// so use async.
display.asyncExec (new Runnable () {
public void run () {
if (!myWindow.isDisposed())
myWindow.redraw ();
}
});
// now do more computations
...
在使用asyncExec 的時(shí)候,在runnable 中檢查圖形部件是否被銷毀是一個(gè)好的習(xí)慣做法,在調(diào)用asyncExec和Runnable執(zhí)行期間主線程中有可能會(huì)發(fā)生其他的事情,不能保證runnable執(zhí)行時(shí)圖形部件當(dāng)前處于什么狀態(tài)。
工作臺(tái)(Workbench)和多線程
實(shí)現(xiàn)SWT應(yīng)用程序的多線程規(guī)則非常明確,你可以控制事件循環(huán)的初始化,在應(yīng)用程序中使用多線程解決復(fù)雜問題。
向工作臺(tái)添加插件時(shí)的工作機(jī)制要父子一些,下面是使用平臺(tái)(workbench platform)UI 類的一些“規(guī)約”(Rules of engagement),隨著eclipse 的不斷發(fā)布,可能會(huì)出現(xiàn)一些例外:
- 通常,任何添加到平臺(tái)中的工作臺(tái)(workbench) UI 擴(kuò)展都是在工作臺(tái)的UI 主線程中執(zhí)行的,除非是明確地把它們添加線程中或者是后臺(tái)作業(yè)(background job)中,例如后臺(tái)作業(yè)進(jìn)度條。
- 如果從工作臺(tái)接收到一個(gè)事件,不能保證它是在UI線程中執(zhí)行的,查閱定義了監(jiān)聽器或事件的類的java文檔,如果沒有特別說明使用線程,這個(gè)類就是一個(gè)UI 相關(guān)類,可以在工作臺(tái)主線程中獲得和運(yùn)行。
- 同樣,除非是文檔明確說明,平臺(tái)UI庫不能視作是線程安全的。請注意,大部分平臺(tái)UI類是在觸發(fā)事件的調(diào)用線程中運(yùn)行監(jiān)聽器的,平臺(tái)和JFace API調(diào)用并不檢查是在UI 線程中執(zhí)行的,這意味著如果在非UI 線程中調(diào)用一個(gè)能夠觸發(fā)事件的方法,可能會(huì)引入問題。從非UI 線程中調(diào)用SWT的API,SWT會(huì)拋出 SWTException 異常。通常,除非文檔中明確規(guī)定,避免在別的線程中調(diào)用平臺(tái)UI 代碼。
- 如果你的插件使用多線程或工作臺(tái)作業(yè)(workbench job),必須使用 Display 類的asyncExec(Runnable) 或 syncExec(Runnable) 方法,類調(diào)用任何的工作臺(tái)(workbench)、JFace或SWT 的應(yīng)用程序接口(API),除非是API明確說明是可以直接調(diào)用的。
- 如果在插件中使用 JFace的IRunnableContext 接口 調(diào)用進(jìn)度監(jiān)視器(progress monitor),以運(yùn)行一個(gè)操作,IRunnableContext 提供了一個(gè)參數(shù)來確定是不是在一個(gè)新的線程中運(yùn)行操作。
附:
posted @
2011-04-17 21:58 Soap MacTavish 閱讀(1488) |
評論 (0) |
編輯 收藏
一.概述
如果你是SWT/Jface的初學(xué)者,那么本片所描述的問題很可能是你已經(jīng)碰到或者將要碰到的。
這是關(guān)于多線程開辟的問題,比較常見。
二.問題:
當(dāng)你在GUI主線程開辟一個(gè)新線程,進(jìn)行其它操作,并且需要更新UI控件,意外發(fā)
生了:
Exception in thread "Thread-1" java.lang.NullPointerException。
三。解決方案
使用:Display#asyncExec(Runnable)或者Display#syncExec(Runnable)。
把你的UI更新操作另開一個(gè)線程,比如:
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
button.setText("update");
}
};
如果其它數(shù)據(jù)處理操作耗時(shí)不長,可以把這部分代碼放入到與UI更新同一個(gè)線程,
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
//Do business action
button.setText("update");
}
};
如果其它數(shù)據(jù)處理耗時(shí)長,那么為了不讓UI響應(yīng)遲鈍,應(yīng)該把邏輯操作和UI更新分開:
Thread t = new Thread(new Runnable() {
public void run() {
//Do business action
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
button.setText("update");
}
};
}
}
posted @
2011-04-17 21:57 Soap MacTavish 閱讀(413) |
評論 (0) |
編輯 收藏
要在后臺(tái)線程里對前臺(tái)界面組件進(jìn)行訪問.
解決方法是使用Display對象,Display對象主要負(fù)責(zé)管理事件循環(huán)和控制UI線程和其它線程之間的通信.
Display.getDefault().asyncExec(new Runnable(){
public void run(){
//對前臺(tái)界面進(jìn)行操作
}
});
- package com.tr069im.ui;
-
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.layout.GridData;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.MessageBox;
- import org.eclipse.swt.widgets.ProgressBar;
- import org.eclipse.swt.widgets.Shell;
-
-
-
-
-
- public class Login implements Runnable {
- private static Shell shell;
- private String loginResponse = "right";
- private static boolean flag = false;
-
- public Login() {
-
- }
-
- public static void main(String[] args) {
-
- final Display display = Display.getDefault();
- shell = new Shell(SWT.MIN);
- shell.setSize(290, 520);
- shell.setLocation(300, 5);
- shell.setText("SWT多線程");
-
-
- final ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL
- | SWT.SMOOTH);
- pb1.setBounds(72, 282, 160, 20);
- pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- pb1.setMinimum(0);
-
- pb1.setMaximum(30);
-
-
- final Button btnLogin = new Button(shell, SWT.FLAT | SWT.PUSH);
- btnLogin.setBounds(80, 363, 111, 36);
- btnLogin.setText("取消");
-
- shell.open();
-
- display.asyncExec(new Runnable() {
- public void run() {
- Login pl = new Login();
- Thread t = new Thread(pl);
- t.start();
- }
- });
-
- Runnable runnable = new Runnable() {
- public void run() {
- for (int i = 0; i < 30; i++) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- display.asyncExec(new Runnable() {
- public void run() {
- if (pb1.isDisposed())
- return;
-
- pb1.setSelection(pb1.getSelection() + 1);
- }
- });
- if (flag) {
- break;
- }
- if (i == 29) {
- open();
- }
- }
- }
- };
- new Thread(runnable).start();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
-
- public void run() {
- try {
-
- if (loginResponse.equals("right")) {
-
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- flag = true;
- Shell shell = new Shell(SWT.MIN);
- MessageBox messageBox = new MessageBox(shell,
- SWT.ICON_WARNING);
- messageBox.setMessage("用戶名或密碼錯(cuò)誤!");
- messageBox.open();
- }
- });
-
- } else {
- }
- } catch (Exception ee) {
- }
- }
-
- public static void open() {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
-
- }
- });
- }
- }
posted @
2011-04-17 21:57 Soap MacTavish 閱讀(1457) |
評論 (0) |
編輯 收藏
S2SH框架集成步驟:
1、框架依賴jar文件
(這些jar包可以去官網(wǎng)自己下載,地址不在連接)
1.1 sping 所依賴工程 spring-framework-2.5.6
dist\spring.jar
lib\cglib\cglib-nodep-2.1_3.jar
lib\jakarta-commons\commons-logging.jar
lib\aspectj\aspectjweaver.jar和aspectjrt.jar lib\j2ee\common-annotations.jar
1.2 hibernate 所依賴工程 hibernate-distribution-3.3.2.GA
hibernate3.jar
lib\required\jta-1.1.jar javassist-3.9.0.GA.jar dom4j-1.6.1.jar commons-collections-3.1.jar antlr-2.7.6.jar slf4j-api-1.5.8.jar
lib\bytecode\cglib\cglib-2.2.jar
[二級(jí)緩存可選]lib\optional\oscache\oscache-2.1.jar 同時(shí)需要把\project\etc\oscache.properties 拷貝到src 下
[二級(jí)緩存可選]lib\optional\ehcache\ehcache-1.2.3.jar 同時(shí)需要把\project\etc\ehcache.xml
[二級(jí)緩存可選]lib\optional\c3p0\ 配置c3p0數(shù)據(jù)庫連接池的使用 作用等同于apache的dbcp
*使用hibernate注解:hibernate-annotations-3.4.0.GA\
hibernate-annotations.jar
lib\hibernate-commons-annotations.jar
lib\ejb3-persistence.jar
*若使用slf的日志還需要:slf4j-1.5.8
slf4j-nop-1.5.8.jar
1.3 struts2 所依賴工程 struts-2.1.8.1
lib目錄下的:
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
ognl-2.7.3.jar
freemarker-2.3.15.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
struts2-spring-plugin-2.1.8.1.jar
aopalliance-1.0.jar
classworlds-1.1.jar
commons-beanutils-1.7.0.jar
commons-chain-1.2.jar
commons-collections-3.2.jar 在hibernate中已經(jīng)引用
commons-digester-2.0.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar 此文件在spring中已存在
commons-logging-api-1.1.jar
commons-validator-1.3.1.jar
ezmorph-1.0.3.jar
json-lib-2.1.jar 若使用json可選
oro-2.0.8.jar
oval-1.31.jar
2、框架的配置文件
2.1 spring框架配置文件及集成hibernate、二級(jí)緩存
$WEB_ROOT/WEB-INF/applicationContext.xml
src/ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
<http://www.springframework.org/schema/beans/spring-beans-2.5.xsd>
<http://www.springframework.org/schema/context> <http://www.springframework.org/schema/context/spring-context-2.5.xsd>
<http://www.springframework.org/schema/aop> <http://www.springframework.org/schema/aop/spring-aop-2.5.xsd>
<http://www.springframework.org/schema/tx> <http://www.springframework.org/schema/tx/spring-tx-2.5.xsd>">
<!-- 配置數(shù)據(jù)源 -->
<context:property-placeholder location="classpath:jdbc4mysql.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 連接池啟動(dòng)時(shí)的初始值 -->
<property name="initialSize" value="${initialSize}" />
<!-- 連接池的最大值 -->
<property name="maxActive" value="${maxActive}" />
<!-- 最大空閑值.當(dāng)經(jīng)過一個(gè)高峰時(shí)間后,連接池可以慢慢將已經(jīng)用不到的連接慢慢釋放一部分,一直減少到maxIdle為止 -->
<property name="maxIdle" value="${maxIdle}" />
<!-- 最小空閑值.當(dāng)空閑的連接數(shù)少于閥值時(shí),連接池就會(huì)預(yù)申請去一些連接,以保證應(yīng)急 -->
<property name="minIdle" value="${minIdle}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>cn/tsp2c/sshdemo/domain/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
</property>
</bean>
<!-- 配置事務(wù)管理器 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- spring支持兩種事務(wù)聲明方式:注解和xml配置,建議使用注解方式 -->
<!-- 采用@Transactional注解方式使用事務(wù),在dao類及方法需用注解方式標(biāo)明事務(wù)方式 -->
<tx:annotation-driven transaction-manager="txManager" />
<!-- 用戶DAO實(shí)現(xiàn),實(shí)現(xiàn)方式:JDBC
<bean id="userDao" class="cn.tsp2c.sshdemo.dao.impl.UserDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
-->
<!-- 用戶DAO實(shí)現(xiàn),實(shí)現(xiàn)方式:hibernte -->
<bean id="userDao" class="cn.tsp2c.sshdemo.dao.impl.hibernate.UserDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 用戶服務(wù)bean -->
<bean id="userService" class="cn.tsp2c.sshdemo.service.impl.UserServiceImpl" >
<property name="userDao" ref="userDao"/>
</bean>
<!-- 用戶Action bean,scope=prototype符合struts2的action生成機(jī)制 -->
<bean id="userAction" class="cn.tsp2c.sshdemo.web.action.UserAction" scope="prototype">
<property name="userService" ref="userService"/>
</bean>
</beans>
其中集成hibernate需要屬性文件:jdbc4mysql.properties
driverClassName=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/sshdemodb?useUnicode\=true&characterEncoding\=utf-8
username=root
password=1234
initialSize=1
maxActive=500
maxIdle=2
minIdle=1
需要配置hibernate的二級(jí)緩存,如使用ehcache:在src路徑下加入ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
defaultCache 設(shè)置節(jié)點(diǎn)為缺省的緩存策略
maxElementsInMemory 設(shè)置內(nèi)存中最大允許存在的對象數(shù)量
eternal 設(shè)置緩存中的對象是否永遠(yuǎn)不過期
overflowToDisk 把超出內(nèi)存設(shè)定的溢出的對象存放到硬盤上
timeToIdleSeconds 設(shè)置緩存對象空閑多長時(shí)間就過期,過期的對象會(huì)被清除掉
timeToLiveSeconds 設(shè)置緩存對象總的存活時(shí)間
diskPersistent 當(dāng)jvm結(jié)束時(shí)是否把內(nèi)存中的對象持久化到磁盤
diskExpiryThreadIntervalSeconds 設(shè)置用于清除過期對象的監(jiān)聽線程的輪詢時(shí)間
-->
<ehcache>
<diskStore path="e:\cache"/>
<defaultCache maxElementsInMemory="1000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="180"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="60"/>
<cache name="cn.tsp2c.sshdemo.domain.User" maxElementsInMemory="100" eternal="false"
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="500" diskPersistent="false"/>
</ehcache>
2.2 struts2的配置文件: src/struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"<http://struts.apache.org/dtds/struts-2.0.dtd>">
<struts>
<!-- 指定web應(yīng)用的默認(rèn)編碼為UTF-8,功能等同于request.setCharacterEncoding() -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<!-- 指定struts2的請求處理后綴,匹配*.action的所有請求 -->
<constant name="struts.action.extension" value="action"/>
<!-- 關(guān)閉struts2的!動(dòng)態(tài)方法調(diào)用,建議使用通配符匹配方式實(shí)現(xiàn)動(dòng)態(tài)方法調(diào)用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<!-- 設(shè)置瀏覽器是否緩存靜態(tài)頁面,默認(rèn)為true,建議:開發(fā)階段關(guān)閉,生產(chǎn)環(huán)境打開 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 當(dāng)struts.xml修改時(shí)自動(dòng)重新加載,默認(rèn)為false。建議:開發(fā)階段打開,生產(chǎn)環(huán)境關(guān)閉 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 開發(fā)模式下打開,便于打印詳細(xì)日志,生產(chǎn)環(huán)境下關(guān)閉 -->
<constant name="struts.devMode" value="true" />
<!-- 設(shè)置視圖主題為css_xhtml -->
<constant name="struts.ui.theme" value="simple" />
<!-- 指定struts中action交由spring創(chuàng)建 -->
<constant name="struts.objectFactory" value="spring"/>
<package name="base" extends="struts-default">
<global-results>
<result name="message">/WEB-INF/page/message.jsp</result>
<result name="error">/WEB-INF/page/error.jsp</result>
</global-results>
</package>
<package name="user" namespace="/user" extends="base">
<action name="login" class="cn.tsp2c.sshdemo.web.action.LoginAction" method="execute">
<result name="success">/index.jsp</result>
<result name="input">/login.jsp</result>
</action>
<action name="user_*" class="cn.tsp2c.sshdemo.web.action.UserAction" method="{1}">
<result name="list">/userlist.jsp</result>
<result name="add" type="redirect">/useradd.jsp</result>
</action>
</package>
</struts>
3、需要把spring、strusts2框架注入到web容器(hibernate框架被spring集成,和web容器沒有關(guān)系。所以不需要在web.xml中配置)
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
<http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd>">
<!-- 配置spring的xml文件,若配置文件有多個(gè),可用,或空格分隔 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- web容器加載struts2配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- web容器加載spring配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- web容器增加字符集轉(zhuǎn)換的過濾器,由于struts2框架解決了字符集轉(zhuǎn)碼,此配置可以注釋掉
<filter>
<filter-name>encoding</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<!-- 解決hibernate的session關(guān)閉導(dǎo)致延遲加載異常的問題 -->
<!--
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.1 web容器集成spring
<!-- 配置spring的xml文件,若配置文件有多個(gè),可用,或空格分隔 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- web容器加載spring配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
3.2 web容器集成struts2
<!-- web容器加載struts2配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.3 關(guān)于在session范圍內(nèi)解決hibernate的延遲加載問題
<!-- 解決hibernate的session關(guān)閉導(dǎo)致延遲加載異常的問題 -->
<filter>
<filter-name>HibernateSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>HibernateSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4、如何使用s2sh框架實(shí)現(xiàn)MVC
4.1 action
struts.xml:
<!-- 指定struts中action交由spring創(chuàng)建 -->
<constant name="struts.objectFactory" value="spring"/>
<action name="user_*" class="cn.tsp2c.sshdemo.web.action.UserAction" method="{1}">
<result name="list">/userlist.jsp</result>
<result name="add" type="redirect">/useradd.jsp</result>
</action>
在spring中配置:
<!-- 用戶Action bean,scope=prototype符合struts2的action生成機(jī)制 -->
<bean id="userAction" class="cn.tsp2c.sshdemo.web.action.UserAction" scope="prototype">
<property name="userService" ref="userService"/>
</bean>
4.2 service
<!-- 用戶服務(wù)bean -->
<bean id="userService" class="cn.tsp2c.sshdemo.service.impl.UserServiceImpl" >
<property name="userDao" ref="userDao"/>
</bean>
4.3 dao
<!-- 用戶DAO實(shí)現(xiàn),實(shí)現(xiàn)方式:JDBC -->
<bean id="userDao" class="cn.tsp2c.sshdemo.dao.impl.UserDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
posted @
2011-03-25 20:18 Soap MacTavish 閱讀(3305) |
評論 (1) |
編輯 收藏
開發(fā)項(xiàng)目涉及到的表太多,一個(gè)一個(gè)的寫JAVA實(shí)體類很是費(fèi)事。MyEclipse提供簡便的方法:反向數(shù)據(jù)庫
***選擇表反向的時(shí)候一次全選上,省的后面配那個(gè)發(fā)現(xiàn)關(guān)聯(lián)表選項(xiàng)
步驟大致如下:
第一步:
window-->open Perspective-->MyEclipse Java Persistence
操作后會(huì)出現(xiàn)一個(gè)視圖DB Brower:MyEclipse Derby
在空白區(qū)點(diǎn)擊右鍵,新建一個(gè)數(shù)據(jù)庫對象。我用的是mysql,其實(shí)我一直想用oracle之類的,只是機(jī)子內(nèi)存小,又懶得倒騰別的,結(jié)果截個(gè)圖吧:
左邊的屬性按照自己使用的數(shù)據(jù)庫填就行了,左邊部分是我建好以后的結(jié)果,數(shù)據(jù)庫名叫shop,有個(gè)user表 是專門這次測試用的

第二步:
新建一個(gè)WEB項(xiàng)目
然后選中項(xiàng)目右鍵-->MyEclipse-->add Hibernate Capabilities
如果需要用到在實(shí)體類上添加注釋的話那么選中緊挨著的add Hibernate Annotations Support(據(jù)說現(xiàn)在都用annotations了就選上吧!!)

然后下一步選中一個(gè)目錄存放自動(dòng)生成hibernate.cfg.xml文件,一般毫無例外的放在src根目錄下,下一步選中一個(gè)DB Driver中我們第一步建立的那個(gè)(對我來說是com.mysql....反正就是自己建的那個(gè)唄),然后下一步選中一個(gè)目錄存放自動(dòng)生成的HibernateSessionFactory工具類 ,結(jié)果出來以后我看了一下,這個(gè)hibernateSessionFactory工具類就是一個(gè)拿Session的單例,還有一些其它關(guān)閉session之類的方法,一看便知。下圖是生成的配置文件:
第三步反向生成實(shí)體類
到DB Brower中找到要反向的表選中并且點(diǎn)擊右鍵--->Hibernate Reverse Enginnering
看選項(xiàng):java src folder 源碼包,不用多解釋,java package——存放將要反轉(zhuǎn)出來的實(shí)體類,選擇目錄(應(yīng)該是提前建好的com.xxx.model之類的包);Create pojo<>db。。。這個(gè)選項(xiàng)選中,就是我們建立從表到簡單java 對象(即pojo)的配置,把下面的add hibernate mapping annotations to pojo的選上,其它不管,這個(gè)選項(xiàng)用來“添加映射注解到pojo對象上”,它上面的那個(gè)選項(xiàng)用來創(chuàng)建xml的,據(jù)說不太用了,就用annotation吧!

這樣應(yīng)該就夠了,下一步
看圖:type Mapping要選上hibernatetypes,這樣這些注解都是來自 javax.persistence.*了 (剛觀察過!)
id generator 看下拉列表就知道是配置id生成策略的
那兩個(gè)enable 是說映射關(guān)系發(fā)現(xiàn)(detection),明白了吧?英文好就是沾光,不用像我一樣還得查字典了。

下一步:沒啥理解不了的 動(dòng)手點(diǎn)點(diǎn)就知道了

直接完成,發(fā)現(xiàn)代碼很漂亮,注釋很完美,而且肯定沒有錯(cuò)誤,幾分鐘都能搞定數(shù)十個(gè)表,不得不感嘆myeclipse,真是個(gè)大金礦。
posted @
2011-03-22 12:52 Soap MacTavish 閱讀(1332) |
評論 (0) |
編輯 收藏
記得剛剛接觸Linux的時(shí)候,自己真是一名不折不扣的菜鳥,通過一年的努力,自己可以單獨(dú)操作Linux了,我將把以后遇到的比較有用的命令積累在這篇博客上。
1. Fedora 版Linux ifconfig
/sbin/ipconfig
2. 設(shè)置tomcat,系統(tǒng)啟動(dòng),同時(shí)tomcat也啟來
echo "/data/webapp/reg/bin/startup.sh">>/etc/rc.local
3. 查看系統(tǒng) Java 進(jìn)程
ps -ef|grep java
4. 設(shè)置動(dòng)態(tài)IP
ifconfig eth0 192.168.1.101 up
5. 在ubuntu下修改文件
gedit /etc/profile
6. netstat –anput 查看端口占有情況
7. killall –9 java 殺死所有系統(tǒng)中java進(jìn)程
8. ./startup.sh ; tail –f /data/webapp/tomcat/logs/catalina.out 啟動(dòng)tomcat,并且查看日志
9. vi編輯文件時(shí),誤寫了,先按ESC 再按u ,可以恢復(fù)。
10. 改變一個(gè)文件夾下所有文件的所有者
chown –R xg.xg folder
11. tomcat 隨著系統(tǒng)自啟動(dòng)
1. 把tomcat和程序放到/home/user
2. 改變tomcat的所有者 chown –R hans.hans tomcat
3. echo "/home/hans/tomcat/startup.sh">>/etc/profile
12. 還有一點(diǎn)要提醒修改linux文件時(shí),一定要先備份
13. 批量修改linux下文件的編碼:
cd /home/hans/test
find ./ -type f -name "*.c"|while read line;do
echo $line
iconv -f GB2312 -t UTF-8 $line > ${line}.utf8
mv $line ${line}.gb2312
mv ${line}.utf8 $line
done
14. vi / vim 編輯文件時(shí),顯示行號(hào)
vim /etc/vimrc
在末行處加上 : set number
Fedora 12 篇
1. Fedora 12 安裝后不能遠(yuǎn)程使用CRT登錄:
ntsysv
出現(xiàn)圖形界面選擇ssh服務(wù)就OK
2. Fedora 12 和 Ubuntu的安裝軟件有所不同
Fedora : yum install gcc
Ubuntu : apt-get install gcc
3. VMware 全屏
首先 Ctrl+Alt+Enter 全屏 但是linux只是占中間的屏幕,這是因?yàn)閘inux的分辨率與window的分辨率不一樣,調(diào)整linux的分辨率和windows一樣就好了。
4. Fedora 9 安裝完后不能使用 ifconfig ,還得這樣:/sbin/ifconfig 才有效
vi /etc/profile
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
修改:把第一行注釋掉
#if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
然后重啟,就好使了!
5. 安裝中文輸入法
yum install scim* -y
posted @
2011-03-06 10:16 Soap MacTavish 閱讀(464) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2011-02-26 11:09 Soap MacTavish 閱讀(408) |
評論 (0) |
編輯 收藏
封裝起來的方法,用到的思路是:
1.規(guī)定好排序規(guī)則,這里用的是根據(jù)第一列升序排序
2.為要排序的列添加好事件響應(yīng)
1.這里是排序規(guī)則及其實(shí)現(xiàn)
package com.bx.ui;
import java.text.Collator;
import java.util.Locale;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class TableColumnSorter {
public static void addNumberSorter(final Table table,
final TableColumn column) {
column.addListener(SWT.Selection, new Listener() {
boolean isAscend = true; // 按照升序排序
public void handleEvent(Event e) {
int columnIndex = getColumnIndex(table, column);
TableItem[] items = table.getItems();
// 使用冒泡法進(jìn)行排序
for (int i = 1; i < items.length; i++) {
String strvalue2 = items[i].getText(columnIndex);
if (strvalue2.equalsIgnoreCase("")) {
// 當(dāng)遇到表格中的空項(xiàng)目時(shí),就停止往下檢索排序項(xiàng)目
break;
}
for (int j = 0; j < i; j++) {
String strvalue1 = items[j].getText(columnIndex);
// 將字符串類型數(shù)據(jù)轉(zhuǎn)化為float類型
float numbervalue1 = Float.valueOf(strvalue1);
float numbervalue2 = Float.valueOf(strvalue2);
boolean isLessThan = false;
if (numbervalue2 < numbervalue1) {
isLessThan = true;
}
if ((isAscend && isLessThan)
|| (!isAscend && !isLessThan)) {
String[] values = getTableItemText(table, items[i]);
Object obj = items[i].getData();
items[i].dispose();
TableItem item = new TableItem(table, SWT.NONE, j);
item.setText(values);
item.setData(obj);
items = table.getItems();
break;
}
}
}
table.setSortColumn(column);
table.setSortDirection((isAscend ? SWT.UP : SWT.DOWN));
isAscend = !isAscend;
}
});
}
public static void addStringSorter(final Table table,
final TableColumn column) {
column.addListener(SWT.Selection, new Listener() {
boolean isAscend = true; // 按照升序排序
Collator comparator = Collator.getInstance(Locale.getDefault());
public void handleEvent(Event e) {
int columnIndex = getColumnIndex(table, column);
TableItem[] items = table.getItems();
// 使用冒泡法進(jìn)行排序
for (int i = 1; i < items.length; i++) {
String str2value = items[i].getText(columnIndex);
if (str2value.equalsIgnoreCase("")) {
// 當(dāng)遇到表格中的空項(xiàng)目時(shí),就停止往下檢索排序項(xiàng)目
break;
}
for (int j = 0; j < i; j++) {
String str1value = items[j].getText(columnIndex);
boolean isLessThan = comparator.compare(str2value,
str1value) < 0;
if ((isAscend && isLessThan)
|| (!isAscend && !isLessThan)) {
String[] values = getTableItemText(table, items[i]);
Object obj = items[i].getData();
items[i].dispose();
TableItem item = new TableItem(table, SWT.NONE, j);
item.setText(values);
item.setData(obj);
items = table.getItems();
break;
}
}
}
table.setSortColumn(column);
table.setSortDirection((isAscend ? SWT.UP : SWT.DOWN));
isAscend = !isAscend;
}
});
}
public static int getColumnIndex(Table table, TableColumn column) {
TableColumn[] columns = table.getColumns();
for (int i = 0; i < columns.length; i++) {
if (columns[i].equals(column))
return i;
}
return -1;
}
public static String[] getTableItemText(Table table, TableItem item) {
int count = table.getColumnCount();
String[] strs = new String[count];
for (int i = 0; i < count; i++) {
strs[i] = item.getText(i);
}
return strs;
}
/*
* table.getColumn(0).addSelectionListener(
new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
//調(diào)用排序文件,處理排序
new TableColumnSorter().addStringSorter(table, table.getColumn(0));
}
});
*
*/
}
2.這里在table中每列實(shí)例化的時(shí)候添加的列監(jiān)聽事件
/*
*
* 添加監(jiān)聽事件
*
*/
table.getColumn(0).addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// 調(diào)用排序文件,處理排序
TableColumnSorter.addStringSorter(table, table
.getColumn(0));
}
});
測試結(jié)果就不在截圖表示
posted @
2011-02-26 10:51 Soap MacTavish 閱讀(835) |
評論 (0) |
編輯 收藏