一开始没有在<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 流浪汗 阅读(589) |
评论 (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 流浪汗 阅读(666) |
评论 (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 流浪汗 阅读(3531) |
评论 (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 流浪汗 阅读(1242) |
评论 (2) |
编辑 收藏
rpm
-
e MySQL
-
server
-
5.1
.
11
-
0
posted @
2007-03-19 20:55 流浪汗 阅读(512) |
评论 (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 流浪汗 阅读(6601) |
评论 (7) |
编辑 收藏
参考:(willpower88兄的blog)
http://www.blogjava.net/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 流浪汗 阅读(2562) |
评论 (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 流浪汗 阅读(2875) |
评论 (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 流浪汗 阅读(539) |
评论 (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 流浪汗 阅读(1565) |
评论 (0) |
编辑 收藏