一開始沒有在<schemaexport />里加
quiet="no" text="true" drop="no" delimiter=";"
???output="${build.class.dir}/schema-export.sql"
運行ant提示失敗
下面是正確的:
<target?name="schema"?depends="build">
????????<taskdef?name="schemaexport"?classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
????????????<classpath?refid="project.classpath"?/>
????????</taskdef>
????????<schemaexport?config="${src.java.dir}/hibernate.cfg.xml"?
????????????quiet="no"?text="true"?drop="no"?delimiter=";"?
????????????output="${build.class.dir}/schema-export.sql"?/>
????</target>
參考:
http://mzrj.itpub.net/post/2660/11489
posted @
2007-03-27 20:58 流浪汗 閱讀(604) |
評論 (0) |
編輯 收藏
要下載iTextAsian.jar
地址: http://prdownloads.sourceforge.net/itext/iTextAsian.jar?download
import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;
BaseFont?bfChinese?=?BaseFont.createFont("STSong-Light",??"UniGB-UCS2-H",?BaseFont.NOT_EMBEDDED);
Font?FontChinese?=?new?Font(bfChinese,?12,?Font.NORMAL);
加入document:
Paragraph?chunk?=?new?Paragraph("中文",?FontChinese);
document.add(chunk);
posted @
2007-03-21 19:52 流浪汗 閱讀(679) |
評論 (0) |
編輯 收藏
目前比較流行的生成Excel文件的有poi和Jexcelapi
poi加中文有問題
必需對每一個Cell設:
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
才不會中文亂碼.沒有找到更好的方法一次性設置所有Cell的字符屬性
用Jexcelapi試下發現不會出現中文問題,是因為它是韓國人寫的吧,以多字節字符為根點
還是喜歡用Jexcelapi
下載:
http://sourceforge.net/project/showfiles.php?group_id=79926:)
posted @
2007-03-21 19:06 流浪汗 閱讀(3572) |
評論 (4) |
編輯 收藏
./configure后時出現ncures / termcap on install 類似的提示
你需要安裝:
termcap-11.0.1-16.noarch.rpm
libtermcap-devel-2.0.8-35.i386.rpm (盤里找到安裝了就可以,其它都安裝了。)
ncurses-5.3-4.i386.rpm
這些文件從安裝光盤上都可以找的到,搜索一下就可以.
make出現exec: g++: not found
yum install gcc-c++-*
chown: 無法訪問 “var”: 沒有那個文件或目錄
改用chown -R mysql data
因為我安裝時用了--localstatedir=/usr/local/mysql/data
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/var --with-charset=gb2312
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &
posted @
2007-03-20 23:01 流浪汗 閱讀(1262) |
評論 (2) |
編輯 收藏
rpm?
-
e?MySQL
-
server
-
5.1
.
11
-
0
posted @
2007-03-19 20:55 流浪汗 閱讀(536) |
評論 (0) |
編輯 收藏
【標 題】:tomcat5下jsp出現getOutputStream() has already been called for this response異常的原因和解決方法
【關鍵字】:tomcat5,jsp,getOutputStream,has,already,been,called,for,this,response
【來 源】:http://blog.csdn.net/alexwan/archive/2007/02/13/1508871.aspx
tomcat5下jsp出現getOutputStream() has already been called for this response異常的原因和解決方法
在tomcat5下jsp中出現此錯誤一般都是在jsp中使用了輸出流(如輸出圖片驗證碼,文件下載等),
沒有妥善處理好的原因。
具體的原因就是
在tomcat中jsp編譯成servlet之后在函數_jspService(HttpServletRequest request, HttpServletResponse response)的最后
有一段這樣的代碼
finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
這里是在釋放在jsp中使用的對象,會調用response.getWriter(),因為這個方法是和
response.getOutputStream()相沖突的!所以會出現以上這個異常。
然后當然是要提出解決的辦法,其實挺簡單的(并不是和某些朋友說的那樣--
將jsp內的所有空格和回車符號所有都刪除掉),
在使用完輸出流以后調用以下兩行代碼即可:
out.clear();
out = pageContext.pushBody();
最后這里是一個輸出彩色驗證碼例子(這樣的例子幾乎隨處可見)
imag.jsp
<% @ page import = " java.awt.*,java.awt.image.*,java.util.*,javax.imageio.* " %>
<% @ page import = " java.io.OutputStream " %>
<%!
Color getRandColor( int fc, int bc){
Random random = new Random();
if (fc > 255 ) fc = 255 ;
if (bc > 255 ) bc = 255 ;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r,g,b);
}
%>
<%
try {
response.setHeader( " Pragma " , " No-cache " );
response.setHeader( " Cache-Control " , " no-cache " );
response.setDateHeader( " Expires " , 0 );
int width = 60 , height = 20 ;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
OutputStream os = response.getOutputStream();
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor( 200 , 250 ));
g.fillRect( 0 , 0 , width, height);
g.setFont( new Font( " Times New Roman " ,Font.PLAIN, 18 ));
g.setColor(getRandColor( 160 , 200 ));
for ( int i = 0 ;i < 155 ;i ++ )
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt( 12 );
int yl = random.nextInt( 12 );
g.drawLine(x,y,x + xl,y + yl);
}
String sRand = "" ;
for ( int i = 0 ;i < 4 ;i ++ ){
String rand = String.valueOf(random.nextInt( 10 ));
sRand += rand;
g.setColor( new Color( 20 + random.nextInt( 110 ), 20 + random.nextInt( 110 ), 20 + random.nextInt( 110 )));
g.drawString(rand, 13 * i + 6 , 16 );
}
session.setAttribute( " rand " ,sRand);
g.dispose();
ImageIO.write(image, " JPEG " ,os);
os.flush();
os.close();
os = null ;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch (IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
} %>
posted @
2007-03-19 12:57 流浪汗 閱讀(6615) |
評論 (7) |
編輯 收藏
參考:(willpower88兄的blog)
http://www.aygfsteel.com/willpower88/archive/2007/01/10/92928.html當我spring中用c3p0時第一次老出現
org.hibernate.exception.JDBCConnectionException: could not execute query
刷新后就不會。一番折騰后直接用<property name="" value="" />就可以了。隨后找到willpower88兄的blog他總結得很好。
環境:
spring 2.0
c3p0-0.9.0.4
spring配置文件如下(引用willpower88兄的,注釋掉的都有問題的):
<bean?id="dataSource"?class="com.mchange.v2.c3p0.ComboPooledDataSource"???destroy-method="close">
?????????<property?name="driverClass"?value="com.mysql.jdbc.Driver"?/>
?????????<property?name="jdbcUrl"?value="jdbc:mysql://localhost/test"/>????????????
?????????<property?name="user"?value="root"/>
?????????<property?name="password"?value=""/>
??????????
?????????<property?name="minPoolSize"?value="2"/>
?????????<property?name="maxPoolSize"?value="20"/>
?????????<property?name="maxIdleTime"?value="1800"/>
?????????<property?name="acquireIncrement"?value="2"/>
?????????<property?name="maxStatements"?value="0"/>
?????????<property?name="initialPoolSize"?value="3"/>
?????????<property?name="idleConnectionTestPeriod"?value="1800"/>
?????????<property?name="acquireRetryAttempts"?value="30"/>
?????????<property?name="breakAfterAcquireFailure"?value="true"/>
?????????<property?name="testConnectionOnCheckout"?value="false"/>
?????????
?????????<!--?
?????????<property?name="properties">
??????????<props>??????????????
??????????????<prop?key="c3p0.minPoolSize">1</prop>?
??????????????<prop?key="c3p0.maxPoolSize">10</prop>?
??????????????<prop?key="c3p0.maxIdleTime">1800</prop>??????????????
??????????????<prop?key="c3p0.acquireIncrement">2</prop>?
??????????????<prop?key="c3p0.maxStatements">0</prop>?
??????????????<prop?key="c3p0.initialPoolSize">2</prop>
??????????????<prop?key="c3p0.idleConnectionTestPeriod">1800</prop>
??????????????<prop?key="c3p0.acquireRetryAttempts">30</prop>
??????????????<prop?key="c3p0.breakAfterAcquireFailure">true</prop>
??????????????<prop?key="c3p0.testConnectionOnCheckout">true</prop>
??????????????<prop?key="user">root</prop>
??????????????<prop?key="password">999999</prop>
??????????????
??????????</props>
?????????</property>
????????-->??????
</bean>
<!--?Hibernate?SessionFactory?-->
<bean?id="sessionFactory"?class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
??<property?name="dataSource"?ref="dataSource"/>
??<property?name="mappingDirectoryLocations">
??????<list>
???<value>classpath:/com/licaionline/domain/</value>
??????</list>
??</property>
??<property?name="hibernateProperties">
???<props>
?????<prop?key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
?????<prop?key="hibernate.show_sql">true</prop>
?????<prop?key="hibernate.generate_statistics">true</prop>
?????<prop?key="hibernate.connection.release_mode">auto</prop>??????????????????????
?????<prop?key="hibernate.autoReconnect">true</prop>
?????<prop?key="hibernate.cglib.use_reflection_optimizer">true</prop>
<!--?
????<prop?key="hibernate.useUnicode"></prop>?
????<prop?key="hibernate.characterEncoding"></prop>
????<prop?key="hibernate.default-lazy-init"></prop>
????<prop?key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>?????
?-->
????????????????????????????????
<!--
????<prop?key="hibernate.c3p0.acquire_increment">2</prop>
????<prop?key="hibernate.c3p0.idle_test_period">1800</prop>
????<prop?key="hibernate.c3p0.timeout">1800</prop>
????<prop?key="hibernate.c3p0.max_size">30</prop>
????<prop?key="hibernate.c3p0.min_size">2</prop>
????<prop?key="hibernate.c3p0.max_statements">50</prop>
-->?????????
???</props>
??</property>
</bean>
posted @
2007-03-18 17:06 流浪汗 閱讀(2581) |
評論 (0) |
編輯 收藏
Tomcat 中Jndi是使用Tomcat自帶的連接池
拋棄Tomcat自帶的連接池。使用c3p0 。
環境:Tomcat 5.5.20
下面配置只適合Tomcat 5.5.X
下面來看Jndi 與 c3p0 結合:
c3p0 下載地址:
http://nchc.dl.sourceforge.net/sourceforge/c3p0/c3p0-0.9.0.4.bin.zip把 c3p0-0.9.0.4.jar 放到應用服務的WEB-INF/lib目錄下。如:DBTest/WEB-INF/lib
1.在server.xml中<Context></Context>內加<Resource />,完整的示例:
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Resource auth="Container"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="50" minPoolSize="2" acquireIncrement="2"
name="jdbc/connPool" user="root" password=""
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/test" />
</Context>
2.在web.xml添加:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/connPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3.測試頁面testConnPool.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/connPool">
select id, typename from text
</sql:query>
<html>
<head>
<title>DB Test Conn Pool c3p0 and Jndi</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
id: ${row.id}<br/>
name: ${row.typename}<br/>
</c:forEach>
</body>
</html>
posted @
2007-03-18 16:46 流浪汗 閱讀(2897) |
評論 (0) |
編輯 收藏
環境:
兩個mysql 5.1.16
一個在win xp主機(192.168.0.158)上,一個在虛擬機的win xp上
1.主服務器的my.ini配置如下(把my-medium.ini復制為my.ini):
在[mysqld]里增加
binlog-do-db=test
binlog-ignore-db=mysql
2.進入主mysql增加復制用戶:
grant?file,select,replication?slave?on?*.*?to?backup@'%'?identified?by?'123456';
3.查看master狀態下重啟下mysql:
show?master?status;
結果為:
+------------------+----------+----------------+--------------------+
| File????????????????????? ?| Position?? | Binlog_Do_DB | Binlog_Ignore_DB? |
+------------------+----------+----------------+--------------------+
| mysql-bin.000003 |?????????102 | test????????????? ??? ?| mysql???????????????? ??? |
+------------------+----------+----------------+--------------------+
1 row in set (0.02 sec)
4.主服務器建表:
create?table?t_repliction?(id?int?not?null?auto_increment?primary?key,name?varchar(255)?);
并加一些數據:
insert?into?t_repliction?(name)?values?('chenlb'),('Tenny');
5.從服務器的my.ini配置如下(同樣把my-medium.ini復制為my.ini):
[mysqld]
server-id=2?
master-host=192.168.0.158
master-user=backup
master-password=123456
master-connect-retry=60
replicate-do-db=test
說明:默認server-id=1要改為2-2^32-1的值,注釋有說明
log-bin=mysql-bin要保留
6.啟動從服務器,并查看狀態:
show?slave?status;
結果:
*************************** 1. row ***************************
???????????? Slave_IO_State: Waiting for master to send event
??????????????? Master_Host: 192.168.0.38
??????????????? Master_User: backup
??????????????? Master_Port: 3306
????????????? Connect_Retry: 60
??????????? Master_Log_File: mysql-bin.000003
??????? Read_Master_Log_Pos: 533
???????????? Relay_Log_File: CLB_0-relay-bin.000006
????????????? Relay_Log_Pos: 243
????? Relay_Master_Log_File: mysql-bin.000003
?????????? Slave_IO_Running: Yes
????????? Slave_SQL_Running: Yes
??????????? Replicate_Do_DB: test
??????? Replicate_Ignore_DB:
???????? Replicate_Do_Table:
???? Replicate_Ignore_Table:
??? Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
???????????????? Last_Errno: 0
???????????????? Last_Error:
?????????????? Skip_Counter: 0
??????? Exec_Master_Log_Pos: 533
??????????? Relay_Log_Space: 1087
??????????? Until_Condition: None
???????????? Until_Log_File:
????????????? Until_Log_Pos: 0
???????? Master_SSL_Allowed: No
???????? Master_SSL_CA_File:
???????? Master_SSL_CA_Path:
??????????? Master_SSL_Cert:
????????? Master_SSL_Cipher:
???????????? Master_SSL_Key:
????? Seconds_Behind_Master: 0
1 row in set (0.00 sec)
ERROR:
No query specified
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
說明成功:
再看是否已經復制test.repliction表
mysql> use test
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t_repliction?? |
+----------------+
1 row in set (0.00 sec)
再看是否有數據
mysql> select * from t_repliction;
+----+--------+
| id | name?? |
+----+--------+
|? 1 | chenlb |
|? 2 | Tenny? |
+----+--------+
2 rows in set (0.01 sec)
:) 有喔
現在在主服務器里加了一條記錄看看有什么結果:
insert?into?t_repliction?(name)?values?('ok');
再在從服務器看看結果:
mysql> select * from t_repliction;
+----+--------+
| id | name?? |
+----+--------+
|? 1 | chenlb |
|? 2 | Tenny? |
|? 3 | ok???? |
+----+--------+
3 rows in set (0.00 sec)
恭喜您成功了 :)
參考:
http://zhhaju.blog.hexun.com/2524561_d.html
posted @
2007-03-16 21:37 流浪汗 閱讀(556) |
評論 (0) |
編輯 收藏
參照:
http://www.360doc.com/showWeb/0/0/207707.aspx環境:
Tomcat 5.5.20
Apache 2.2.3
1.機器A 里有TomcatA\webapps\Test目錄, 機器B里TomcatB\webapps\Test目錄。其web.xml文件一樣,兩個都在</web-app>之前加上<distributable/>
2.兩個Tomcat\conf\server.xml的如下內容去掉注釋,沒有就在</Host>之前加上去:
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true"
notifyListenersOnReplication="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"
ackTimeout="15000"
waitForAck="true"/>
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>
</Cluster>
3.接下來配置Apache\conf\httpd.conf
其中這三個去掉注釋:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
末尾加上:
ProxyRequests Off
ProxyPass /helloworld balancer://mycluster stickysession=jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://192.168.0.100:8080
BalancerMember http://192.168.0.101:8080
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from all
</Location>
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all
</Location>
說明:
ProxyPass /helloworld balancer://mycluster stickysession=jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://192.168.0.100:8080
BalancerMember http://192.168.0.101:8080
</Proxy>
ProxyPass為代理轉發的Url,即將所有訪問/helloworld的請求轉發到群集balancer://mycluster
BalancerMember為群集的成員,即群集服務器A或B,負載均衡服務器會根據均衡規則來將請求轉發給BalancerMember。
4.測試頁面,
TomcatA\webapps\Test\index.html內容如下:
<html>
<head><title>Tomcat 5.5.20 群集1</title></head>
<body>
<center>Tomcat 1號機
</center>
</body>
</html>
TomcatB\webapps\Test\index.html內容如下:
<html>
<head><title>Tomcat 5.5.20 群集2</title></head>
<body>
<center>Tomcat 2號機在TomcatB機上
</center>
</body>
</html>
啟動TomcatA和TomcatB,再啟動Apache
http://localhost/helloworld/Test/index.html
后有出現上面兩個頁面的任一個說明配置成功。
不斷刷新,這個頁面不斷交替。
:)
posted @
2007-03-15 16:59 流浪汗 閱讀(1581) |
評論 (0) |
編輯 收藏