http://www.javacamp.org/designPattern/
http://www.fluffycat.com/Java-Design-Patterns/Composite/
http://www.javaworld.com/channel_content/jw-patterns-index.html
posted @
2007-04-03 08:37 选宝网an9 阅读(283) |
评论 (0) |
编辑 收藏
默认安装tomcat5然后在catalina.bat最前面加入set JAVA_OPTS=-Xms128m -Xmx350m 如果用startup.bat启动tomcat,OK设置生效.够成功的分配200M内存.
但是如果不是执行startup.bat启动tomcat而是利用windows的系统服务启动tomcat服务,上面的设置就不生效了,就是说set JAVA_OPTS=-Xms128m -Xmx350m 没起作用.上面分配200M内存就OOM了..
windows服务执行的是bin\tomcat.exe.他读取注册表中的值,而不是catalina.bat的设置.
解决办法:
修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat Service Manager\Tomcat5\Parameters\JavaOptions
原值为
-Dcatalina.home="C:\ApacheGroup\Tomcat 5.0"
-Djava.endorsed.dirs="C:\ApacheGroup\Tomcat 5.0\common\endorsed"
-Xrs
加入 -Xms300m -Xmx350m
重起tomcat服务,设置生效
posted @
2007-03-27 10:49 选宝网an9 阅读(1020) |
评论 (0) |
编辑 收藏
http://java.sun.com/docs/books/tutorial/javabeans/introspection/index.html
posted @
2007-03-21 08:04 选宝网an9 阅读(140) |
评论 (0) |
编辑 收藏
1.mysql在本地localhost的test数据库 建person表,暂以字段id,name,password ,表中可输入一行值.
2.建类 DAOUtil
import java.sql.Connection;
import java.sql.DriverManager;
public class DAOUtil {
public DAOUtil() {
}
public static Connection getConn() {
Connection conn = null;
String db_url = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=gb2312";
String db_user = "root";
String db_password= "admin";
String db_driver = "com.mysql.jdbc.Driver";
try {
Class.forName(db_driver);
conn = DriverManager.getConnection(db_url, db_user, db_password);
} catch (Exception ex) {
ex.printStackTrace();
}
return conn;
}
/**
* dbclose
* 关闭Connection,Statement
* @param conn Connection
* @param stmt Statement
*/
public static void dbclose(Connection conn, Statement stmt) {
try {
if (stmt != null)
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
if (conn != null)
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
3.建类 PersonDAO
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
public class PersonDAO {
static PersonDAO pdao;
public static PersonDAO getInstance() {
if (pdao == null) {
synchronized (PersonDAO.class) {
pdao = new PersonDAO();
}
}
return pdao;
}
public PersonDAO() {
super(); }
public static void main(String[] args) {
System.out.println("person==="+PersonDAO.getInstance().getPersonInfo());
}
private static List getPersonInfo() {
String name = "";
String password = "";
Connection conn = null;
List list = new java.util.ArrayList();
Statement stmt = null;
String sql =
"select name,password from person";
try {
conn = DAOUtil.getConn();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
name = (String)rs.getString("name");
password = (String)rs.getString("password");
list.add(name+","+password);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
DAOUtil.dbclose(conn, stmt);
}
return list;
}
}
4.建testCache.jsp,testCache2.jsp
<%@page contentType="text/html; charset=GBK"%>
<%@page import="com.mcsky.dao.PersonDAO" session="false"%>
<%@page import="java.util.List" session="false"%>
<html>
<body bgcolor="#FFFFFF">
test ,hello world!!<p>
<table width="85%" border="1" align="center">
<tr>
<td width="8%" height="20"> <div align="center">序号</div></td>
<td width="12%"><div align="center">名字</div></td>
<td width="17%"><div align="center">密码 </div></td>
</tr>
<%
//todo connect mysql server (localhost root/admin) and test(db) person(table)
List list =PersonDAO.getInstance().getPersonInfo();
System.out.println("size==="+list.size());
for(int i=0;i<list.size();i++){
String namePass = (String)list.get(i);
java.util.StringTokenizer st = new java.util.StringTokenizer(namePass,",");
String name = st.nextToken();
String pass = st.nextToken();
System.out.println("namePass+++++"+namePass);
%>
<tr>
<td><div align="center"><%=i+1%></div></td>
<td> <div align="center"><%=name%></div></td>
<td><div align="center"><%=pass%></div></td>
</tr>
<%
}
%>
</table>
</body>
</html>
5.把module部署在tomcat的webapp下
5.1 在WEB-INF\lib\log4j-1.2.8.jar,mysql-connector-java-3.0.11-stable-bin.jar,oscache-2.3.2.jar,commons-logging.jar,jgroups-all.jar
5.2 在WEB-INF\classes拷贝cach\etc\下的oscache.tld,oscache.properties
5.3 只对/testCache.jsp缓存
修改WEB-INF\web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>test</display-name>
<taglib><taglib-uri>oscache</taglib-uri><taglib-location>/WEB-INF/classes/ oscache.tld</taglib-location></taglib>
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>/testCache.jsp</url-pattern>
</filter-mapping>
</web-app>
启动tomcat,在mysql的person中增加一条记录,发现已对/testCache.jsp页面进行缓存,而/testCache2.jsp页面未缓存,如去掉黑体,则数据表增加一行,testCache.jsp也随之修改
5.4对所有的jsp缓存,
修改WEB-INF\web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>test</display-name>
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
<init-param>
<param-name>time</param-name>
<param-value>60</param-value>
</init-param>
<init-param>
<param-name>scope</param-name>
<param-value>session</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter
</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
</web-app>
其中60s,是失效时间,在mysql的person中增加一条记录,发现已对/testCache.jsp,/testCache2.jsp页面进行缓存,页面不变化,60s后页面变化.
posted @
2007-03-17 09:15 选宝网an9 阅读(218) |
评论 (0) |
编辑 收藏
我想把一个基于数据库的WEB应用程序加上缓存,以提高性能,开源的java缓存系统不少,先拿JCS( Java Caching System)试试。
关于JCS的介绍,小红帽的文章已写得非常清楚了,附后。
先到http://jakarta.apache.org/jcs/Downloads.html
下载jcs-1.2.6.jar,找了半天也没有找到它的源码和API文档,不知为什么?
在这个站点有: Using JCS: Some basics for the web ,不错,就用它练习。
一、创建值对象
假设有一BOOK,它在数据库中的表为:
Table BOOK
BOOK_ID_PK
TITLE
AUTHOR
ISBN
PRICE
PUBLISH_DATE
创建值对象如下:
package com.genericbookstore.data;
import java.io.Serializable;
import java.util.Date;
public class BookVObj implements Serializable
{
public int bookId = 0;
public String title;
public String author;
public String ISBN;
public String price;
public Date publishDate;
public BookVObj()
{
}
}
二、创建缓存管理器
应用中对book数据的访问都通过缓存管理器。
package com.genericbookstore.data;
import org.apache.jcs.JCS;
// in case we want to set some special behavior
import org.apache.jcs.engine.behavior.IElementAttributes;
public class BookVObjManager
{
private static BookVObjManager instance;
private static int checkedOut = 0;
public static JCS bookCache;
private BookVObjManager()//构造函数
{
try
{
bookCache = JCS.getInstance("bookCache");
}
catch (Exception e)
{
// Handle cache region initialization failure
}
// Do other initialization that may be necessary, such as getting
// references to any data access classes we may need to populate
// value objects later
}
/**
* Singleton access point to the manager.
*/
public static BookVObjManager getInstance()
{
synchronized (BookVObjManager.class)
{
if (instance == null)
{
instance = new BookVObjManager();
}
}
synchronized (instance)
{
instance.checkedOut++;
}
return instance;
}
/**
* Retrieves a BookVObj. Default to look in the cache.
*/
public BookVObj getBookVObj(int id)
{
return getBookVObj(id, true);
}
/**
* Retrieves a BookVObj. Second argument decides whether to look
* in the cache. Returns a new value object if one can't be
* loaded from the database. Database cache synchronization is
* handled by removing cache elements upon modification.
*/
public BookVObj getBookVObj(int id, boolean fromCache)
{
BookVObj vObj = null;
// First, if requested, attempt to load from cache
if (fromCache)
{
vObj = (BookVObj) bookCache.get("BookVObj" + id);
}
// Either fromCache was false or the object was not found, so
// call loadBookVObj to create it
if (vObj == null)
{
vObj = loadBookVObj(id);
}
return vObj;
}
/**
* Creates a BookVObj based on the id of the BOOK table. Data
* access could be direct JDBC, some or mapping tool, or an EJB.
*/
public BookVObj loadBookVObj(int id)
{
BookVObj vObj = new BookVObj();
vObj.bookId = id;
try
{
boolean found = false;
// load the data and set the rest of the fields
// set found to true if it was found
found = true;
// cache the value object if found
if (found)
{
// could use the defaults like this
// bookCache.put( "BookVObj" + id, vObj );
// or specify special characteristics
// put to cache
bookCache.put("BookVObj" + id, vObj);
}
}
catch (Exception e)
{
// Handle failure putting object to cache
}
return vObj;
}
/**
* Stores BookVObj's in database. Clears old items and caches
* new.
*/
public void storeBookVObj(BookVObj vObj)
{
try
{
// since any cached data is no longer valid, we should
// remove the item from the cache if it an update.
if (vObj.bookId != 0)
{
bookCache.remove("BookVObj" + vObj.bookId);
}
// put the new object in the cache
bookCache.put("BookVObj" + vObj.bookId, vObj);
}
catch (Exception e)
{
// Handle failure removing object or putting object to cache.
}
}
}
三、配置文件cache.ccf,它定义你配置何种类型的缓存、缓存的大小、过期时间等。
#WEB-INF/classes/cache.ccf(以下内容不要换行)
jcs.default=
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.cacheattributes.MaxSpoolPerRun=500
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
四、测试的JSP文件
<%@page import="com.genericbookstore.data.*,java.util.*" %>
<%
BookVObjManager cache = BookVObjManager.getInstance();
BookVObj bv1=cache.getBookVObj(8,true);
out.println(bv1.bookId);
%>
五、测试:http://127.0.0.1:8080/jcs/testjcs.jsp
所有源文件请下载。
附:
JCS(Java Caching System)简介以及相关文档作者:小红帽
概述
JCS是Jakarta的项目Turbine的子项目。它是一个复合式的缓冲工具。可以将对象缓冲到内存、硬盘。具有缓冲对象时间过期设定。还可以通过JCS构建具有缓冲的分布式构架,以实现高性能的应用。
对于一些需要频繁访问而每访问一次都非常消耗资源的对象,可以临时存放在缓冲区中,这样可以提高服务的性能。而JCS正是一个很好的缓冲工具。缓冲工具对于读操作远远多于写操作的应用性能提高非常显著。
JCS的详细说明在 http://jakarta.apache.org/turbine/jcs/
JCS的特性
JCS除了简单的将对象缓冲在内存中以外,还具有几个特性,以适应企业级缓冲系统的需要。这些特性包括时间过期、索引式硬盘缓冲、并行式的分布缓冲等。
内存缓冲
JCS现在支持两种内存缓冲算法LRU和MRU。通常都是使用LRU算法。
org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
使用内存缓冲区需要定义缓冲区大小,当超过缓冲区限制时,会将缓冲内容抛弃掉。如果有配硬盘缓冲,则将挤出来的缓冲内容写入硬盘缓冲区。
时间过期
JCS对于缓冲的对象,可以设定缓冲过期时间,一个对象在缓冲区中停留的时间超过这个时间,就会被认为是“不新鲜”而被放弃。
索引式硬盘缓冲
一方面,为了避免缓冲区过大,撑爆虚拟机的内存,另一方面又希望能够缓冲更多的对象,JCS可以将超出缓冲区大小的对象缓存到硬盘上。配置上也比较方便, 只需要指定缓冲临时文件的存放目录位置。硬盘缓冲将缓冲对象的内容写到文件上,但是将访问索引保存在内存中,因此也能够达到尽可能高的访问效率。
并行式的分布缓冲(Lateral)
通常,将对象缓冲在内存中,一方面提高了应用的性能,而另一方面却使得应用不可以分布式发布。因为假设一个应用配置在两台服务器上并行运行,而两台服务器 单独缓冲,则很容易导致两个缓冲区内容出现版本上的不一致而出错。一个机器上修改了数据,这个动作会影响到本地内存缓冲区和数据库服务器,但是却不会通知 到另一台服务器,导致另一台上缓冲的数据实际上已经无效了。
并行式的分布缓冲就是解决这个问题。可以通过配置,将几台服务器配成一个缓冲组,组内每台服务器上有数据更新,会横向将更新的内容通过TCP/IP协议传 输到其他服务器的缓冲层,这样就可以保证不会出现上述情况。这个的缺点是如果组内的并行的服务器数量增大后,组内的数据传输量将会迅速上升。这种方案适合 并行服务器的数量比较少的情况。
Client/Server式的缓冲(Remote)
客户/服务端式的缓冲集群。这种方式支持一个主服务器和最高达到256个客户端。客户端的缓冲层会尝试连接主服务器,如果连接成功,就会在主服务器上注册。每个客户端有数据更新,就会通知到主服务器,主服务器会将更新通知到除消息来源的客户端以外的所有的客户端。
每个客户端可以配置超过一个服务器,第一个服务器是主服务器,如果与第一个服务器连接失败,客户端会尝试与备用的服务器连接,如果连接成功,就会通过备用 服务器与其他客户端对话,同时会定期继续尝试与主服务器取得连接。如果备用服务器也连接失败,就会按照配置顺序尝试与下一个备用服务器连接。
这种方式下,更新通知是一种轻量级的,一个机器上的数据更新,不会把整个数据传输出去,而只是通知一个ID,当远程的其他机器收到更新通知后,就会把对应ID的缓冲对象从本地的内存缓冲区中移除,以保证不会在缓冲区内出现错误数据。
这种构造需要分别配置客户端和服务器,配置比较麻烦。
配置方法
JCS的好处之一,就是应用在开发的时候,可以不用去构思底层的缓冲配置构架。同一个应用,只需要修改配置,就可以改变缓冲构架,不需要修改应用的源代 码。配置方法也比较简单,就是修改配置文件cache.ccf。这个文件放置在WEB-INF/classes目录下。配置格式类似log4j的配置文件 格式。下面介绍一下使用各种缓冲结构的配置方法。
内存缓冲
#WEB-INF/classes/cache.ccf(以下内容不要换行)
jcs.default=
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
上面配置了默认缓冲属性。一个应用中,由于对象类型的不同,可能会使用多个缓冲区,每个缓冲区都会有一个名字,如果在配置文件中没有指明特定的缓冲区的属 性,所有的缓冲区都会根据默认属性来构建。上面的内容,指明缓冲区的大小为存放1000个对象,内存缓冲器使用LRUMemoryCache对象。可选的 还有MRUMemoryCache,应该可以自定义新的内存缓冲区。1000个缓冲对象这个容量,是指每个缓冲区都缓冲1000个,而不是指所有缓冲区总 容量。以上配置,就可以让应用运行起来。
时间过期
如果需要引入时间过期机制,则需要加上
jcs.default.cacheattributes.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.cacheattributes.ShrinkerIntervalSeconds=60
这里指明对象超过3600秒则过期,每隔60秒检查一次。
索引式硬盘缓冲
索引式硬盘缓冲是辅助缓冲的一种,使用时需要做以下事情
#定义一个硬盘缓冲区产生器(Factory),取名为DC
jcs.auxiliary.DC=org.apache.stratum.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.stratum.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=g:/dev/jakarta-turbine-stratum/raf
#这里其实就是指明了缓冲文件存放到那里去。
然后,做以下修改
jcs.default=DC
这样,所有未特别指定属性的缓冲区都会自己使用一个硬盘缓冲区,缓冲文件会以缓冲区的名字来命名。存放在指定的目录下。
横向式的并行缓冲
并行式的配置如下
jcs.auxiliary.LTCP=org.apache.jcs.auxiliary.lateral.LateralCacheFactory
jcs.auxiliary.LTCP.attributes=org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
jcs.auxiliary.LTCP.attributes.TcpServers=192.168.10.129:1121,192.168.10.222:1121
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1121
jcs.auxiliary.LTCP.attributes.PutOnlyMode=false
这里的配置是在41,129,221三台机器上实现并行缓冲的。
大家都在1121端口上监听,同时与另外两台机器连接。如果连接失败,就会等待一个时间后再连接一次,直到连接成功为止。三台机器中任意一台的缓冲区发生更新,比如put和remove动作,就会把更新传递给另外两台。
单独指明某个缓冲区的属性
如果,针对某个缓冲区,比如叫做TestCache1,需要单独配置属性,可以如下配置。
jcs.region.testCache1=DC,LTCP
jcs.region.testCache1.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=1000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=60
system.GroupIdCache
这个概念我也不是很清楚。不过JCS文档中指出配置以下内容会比较好。
jcs.system.groupIdCache=DC
jcs.system.groupIdCache.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
这可能是JCS自己的组管理体系上的缓冲区。
Client/Server式的缓冲(Remote)
这种构架需要单独配置客户端和服务端,如果要研究,可以查看 http://jakarta.apache.org/turbine/jcs/RemoteAuxCache.html
posted @
2007-03-17 09:14 选宝网an9 阅读(288) |
评论 (0) |
编辑 收藏
摘要:
阅读全文
posted @
2007-03-02 11:06 选宝网an9 阅读(412) |
评论 (0) |
编辑 收藏
从
数据库中读出图片并显示的示例代码
< !-- -- -- --
Servlet-- -- -- -- -->
package Photo;
import
Javax.servlet.*;
import
javax.servlet.http.*;
import
java.io.*;
import
java.util.*;
import
java.lang.*;
import
java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class ShowImage extends HttpServlet {
private static final String CONTENT_TYPE = "image/*";
/**
* 定义数据库连接字符串,JDBC.odbc桥
*/
private String driver_class = "Oracle.jdbc.driver.OracleDriver";
private String connect_string =
"jdbc:oracle:thin:xxw/xxw@192.168.1.50:1521:ORCL";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
/********************************************
* 定义应用变量
******************************************/
private String SQLString = ""; //定义查询语句\\r
public String M_EorrMenage = ""; //定义错误信息变量
private InputStream in = null; //定义输入流\\r
private int len = 10 * 1024 * 1024; //定义字符数组长度
//Initialize global variables
public void init() throws ServletException {
/**
* 连接数据库\\r
*/
try {
Class.forName(driver_class);
} catch (java.lang.ClassNotFoundException e) {
//异常
System.err.println("databean():" + e.getMessage());
}
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
//在数据库中的照片的ID
int PHOTOID = 0;
/*********************************************
* 接受上文传递的图片ID号
* 上文传输文件名称为photoid
*********************************************/
try {
PHOTOID = Integer.parseInt(request.getParameter("photoid"));
SQLString = "select * from xxw_photo where p_id=" + PHOTOID;
} catch (Exception e) {
e.printStackTrace();
response.setContentType("text/html; charset=gb2312");
M_EorrMenage = "请输入图片ID号";
M_EorrMenage =
new String(M_EorrMenage.getBytes("ISO8859_1"), "GBK");
out.println("<%@ page contentType=\'text/html; charset=gb2312\' %>");
out.println("<html>");
out.println("<head><title>id</title></head>");
out.println("<body>");
out.println("<p>" + M_EorrMenage + "</p>");
out.println("</body></html>");
}
/*****************************************************
* 执行查询语句\\r
*****************************************************/
try {
conn = DriverManager.getConnection(connect_string);
stmt = conn.createStatement();
rs = stmt.executeQuery(SQLString);
} //try
catch (SQLException ex) {
System.err.println("aq.executeUpdate:" + ex.getMessage());
M_EorrMenage = "对不起,数据库无法完成此操作!";
M_EorrMenage =
new String(M_EorrMenage.getBytes("ISO8859_1"), "GBK");
response.setContentType("text/html; charset=gb2312");
out.println("<html>");
out.println("<head><title>no_database</title></head>");
out.println("<body>");
out.println("<p>" + M_EorrMenage + "</p>");
out.println("</body></html>");
}
/*********************************************
* 将图片流读入字符数组中,并显示到客户端
********************************************/
try {
if (rs.next()) {
in = rs.getBinaryStream("photo");
response.reset(); //返回在流中被标记过的位置
response.setContentType("image/jpg"); //或gif等
// int len=in.available();//得到文件大小
OutputStream toClient = response.getOutputStream();
byte[] P_Buf = new byte[len];
int i;
while ((i = in.read(P_Buf)) != -1) {
toClient.write(P_Buf, 0, i);
}
in.close();
toClient.flush(); //强制清出缓冲区\\r
toClient.close();
} else {
M_EorrMenage = "无此图片!";
M_EorrMenage =
new String(M_EorrMenage.getBytes("ISO8859_1"), "GBK");
response.setContentType("text/html; charset=gb2312");
out.println("<html>");
out.println(
"<head><title>this photo isn\'t have</title></head>");
out.println("<body>");
out.println("<p>" + M_EorrMenage + "</p>");
out.println("</body></html>");
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
M_EorrMenage = "无法读取图片!";
M_EorrMenage =
new String(M_EorrMenage.getBytes("ISO8859_1"), "GBK");
response.setContentType("text/html; charset=gb2312");
out.println("<%@ page contentType=\'text/html; charset=gb2312\' %>");
out.println("<html>");
out.println("<head><title>no photo</title></head>");
out.println("<body>");
out.println("<p>" + M_EorrMenage + "</p>");
out.println("</body></html>");
}
}
//Clean up resources
public void destroy() {
try {
conn.close();
} catch (SQLException e) {
System.err.println("aq.executeUpdate:" + e.getMessage());
M_EorrMenage = "对不起,数据库无法完成此操作!";
}
}
}
<!---------------------------显示---------------------------------------------->
<html>
<head>
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table>
<%
int i=1;
while(i<3){
%>
<tr>
<td colspan="3"> <img border="1" src="http://192.168.1.50:8100/ShowImage?photoid=<%=i%>"></td>
</tr>
<%
i++;
}
%>
</table>
</body>
</html>
posted @
2006-11-21 19:54 选宝网an9 阅读(618) |
评论 (0) |
编辑 收藏
(转载)这个是DBunit的问题,1.8以上的版本才有这个问题!
只要修改User.java
/**
* @return Returns the enabled.
* @hibernate.property column="enabled"
*/
public Boolean getEnabled() {
// isEnabled doesnt' work for copying properties to Struts ActionForms
return enabled;
}
修改成
/**
* @return Returns the enabled.
* @hibernate.property column="enabled"
type="yes_no" */
public Boolean getEnabled() {
// isEnabled doesnt' work for copying properties to Struts ActionForms
return enabled;
}
就加了这一点,就可以了,
其实 type="yes_no" hibernate会映射成CHAR(1) , 而type="boolean" 它会映射成BIT , 估计dbunit在插入sample-data.xml的时候会出错。
posted @
2006-10-26 14:15 选宝网an9 阅读(333) |
评论 (0) |
编辑 收藏
解决此问题,应该这样写:
window.location.href=window.location.href;
window.location.reload;
同理,如果是刷新父窗口,应该这样写:
window.opener.location.href=window.opener.location.href;
window.location.reload;
这种写法就不出现那讨厌的对话框啦!
posted @
2006-10-23 13:43 选宝网an9 阅读(270) |
评论 (0) |
编辑 收藏
<script defer>
function SetPrintSettings() {
// -- advanced features
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"
// -- basic features
factory.printing.header = "This is MeadCo"
factory.printing.footer = "Advanced Printing by ScriptX"
factory.printing.portrait = false
factory.printing.leftMargin = 1.0
factory.printing.topMargin = 1.0
factory.printing.rightMargin = 1.0
factory.printing.bottomMargin = 1.0
}
</script>
<script language="javascript">
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
document.getElementById('button1').style.display='none';
document.getElementById('button2').style.display='none';
document.getElementById('button3').style.display='none';
document.getElementById('button4').style.display='none';
wb.execwb(7,1);
location.reload();
}
function printit()
{
if (confirm('确定打印吗?')) {
wb.execwb(6,6)
}
}
</script>
</head>
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button name=button_print value="打印" onclick="printit()" id="button1">
<input type=button name=button_setup value="打印页面设置" onclick="printsetup();" id="button2">
<input type=button name=button_show value="打印预览" onclick="printpreview();" id="button3">
<input type=button name=button_fh value="关闭" onclick="javascript:window.close();" id="button4">
<TABLE width="90%" cellspacing="0" bordercolordark="#CEDAE7" cellpadding="1" align="center" bordercolorlight="#155BBD" border="1">
<TBODY>
<THEAD style="display:table-header-group;font-weight:bold">
<TR>
<TD width=73 rowspan="2" align="center">
专家姓名
</TD>
<TD height="31" colspan="4" align="center">
次数
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=25 onMouseOut="this.bgColor='#CEE5FF'" bgColor=#f2fff4>
<TD width="147" height=25 bgcolor="#94C0F1" align="center">
正常参加
</TD>
<TD width="108" height=25 bgcolor="#94C0F1" align="center">
拒绝参加
</TD>
<TD width="124" height=25 bgcolor="#94C0F1" align="center">
未通知
</TD>
<TD width="88" height=25 bgcolor="#94C0F1" align="center">
总数
</TD>
</TR>
</THEAD>
<!-- 所有专家 -->
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000020';" onMouseOut="this.bgColor='#FfffFF'" bgColor=#ffffff>
<TD>
<DIV align=center>
fsdfs
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000022';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
ggafds
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000029';" onMouseOut="this.bgColor='#FfffFF'" bgColor=#ffffff>
<TD>
<DIV align=center>
王五
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000050';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
余敏
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000061';" onMouseOut="this.bgColor='#FfffFF'" bgColor=#ffffff>
<TD>
<DIV align=center>
江泽民
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000064';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
袁平1
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000093';" onMouseOut="this.bgColor='#FfffFF'" bgColor=#ffffff>
<TD>
<DIV align=center>
zzz
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000112';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
冶金专家1
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000113';" onMouseOut="this.bgColor='#FfffFF'" bgColor=#ffffff>
<TD>
<DIV align=center>
冶金专家2
</DIV>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<TR onMouseOver="this.bgColor='#94C0F1'" style="CURSOR: hand" height=22 onclick="location='expertInfo.do?exp_id=EP00000002';" onMouseOut="this.bgColor='#CEE5FF'" bgColor=#DAE5F9>
<TD>
<DIV align=center>
fds
</DIV>
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
<TD align=center>
0
</TD>
<TD align=center>
0
</TD>
<TD align=center>
<font color='red'>1</font>
</TD>
</TR>
<!-- 正常参加专家 -->
<!-- 拒绝专家 -->
</TBODY>
<TFOOT style="display:table-footer-group;font-weight:bold">
<TR>
<TD colspan="2" align="center" style="font-weight:bold;border:3px double blue">
每页都有的表尾
</TD>
</TR>
</TFOOT>
</TABLE>
</body>
posted @
2006-10-13 12:39 选宝网an9 阅读(299) |
评论 (0) |
编辑 收藏