??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲女成人图区,国产在线观看高清视频,日韩成人精品在线http://www.aygfsteel.com/yidishui/java 2006q?月新开?)zh-cnFri, 04 Jul 2025 02:02:37 GMTFri, 04 Jul 2025 02:02:37 GMT60Struts 中文q问题 Filter解决http://www.aygfsteel.com/yidishui/archive/2006/09/08/68581.html一滴水一滴水Fri, 08 Sep 2006 10:41:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/09/08/68581.htmlhttp://www.aygfsteel.com/yidishui/comments/68581.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/09/08/68581.html#Feedback1http://www.aygfsteel.com/yidishui/comments/commentRss/68581.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/68581.htmlq个也不知道来自|上那里Q自qq了Q最q整理资料记录下?/p>

原理很简单就是用Filter处理讄的请求的 CharacterEncoding

具体实现Filter

package yidishui.util;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class EncodingFilter implements Filter {
/**
* The default character encoding to set for requests that pass through this
* filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value is
* null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param chain The filter chain we are processing
* @throws IOException if an input/output error occurs
* @throws ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
// ------------------------------------------------------ Protected Methods
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p/>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
* @return return encoding
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}// EOC
 

2.具体web.xml配置

<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>yidishui.util.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>yes</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


一滴水 2006-09-08 18:41 发表评论
]]>
An Introduction To JSTLhttp://www.aygfsteel.com/yidishui/archive/2006/08/21/64835.html一滴水一滴水Mon, 21 Aug 2006 09:20:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/08/21/64835.htmlhttp://www.aygfsteel.com/yidishui/comments/64835.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/08/21/64835.html#Feedback0http://www.aygfsteel.com/yidishui/comments/commentRss/64835.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/64835.html阅读全文

一滴水 2006-08-21 17:20 发表评论
]]>
FCKEditor 在JSP中?/title><link>http://www.aygfsteel.com/yidishui/archive/2006/08/17/64121.html</link><dc:creator>一滴水</dc:creator><author>一滴水</author><pubDate>Thu, 17 Aug 2006 06:25:00 GMT</pubDate><guid>http://www.aygfsteel.com/yidishui/archive/2006/08/17/64121.html</guid><wfw:comment>http://www.aygfsteel.com/yidishui/comments/64121.html</wfw:comment><comments>http://www.aygfsteel.com/yidishui/archive/2006/08/17/64121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yidishui/comments/commentRss/64121.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yidishui/services/trackbacks/64121.html</trackback:ping><description><![CDATA[FCKEditor 在JSP中?<br />1.下蝲FCKEditor2.3.1<br />2.下蝲FCKeditor.Java<br />====================<br />清理FCKEdior:<br />  1>删除 _samples 里面是例?_testcases 试 要更详细高使用查例子和试,q有一下文件不用的删除<br />  2>删除 editor\_source 可能是源代码?没有仔细研究<br />  3> editor\filemanager\browser\default\connectors 删除,使用的是servlet来操作的(使用其它语言的话pҎ(gu)情况处理?<br />     editor\filemanager\upload 删除,同样使用的是servlet<br />  4>editor\lang 语言文g,Ҏ(gu)具体应用处理<br />  5>editor\skins  删除不是用的skins<br />====================<br />基本使用:<br />1>把FCKEdior拯到根目录<br />2>拯FCKeditor.Java 例子里面的FCKeditor-2.3.jar文g<br />3>修改fckconfig.js<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">  FCKConfig.DefaultLanguage </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> 'zh</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">cn' 默认语言<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />  FCKConfig.ToolbarSets[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Default</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">] 讄工具?br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />  FCKConfig.ContextMenu 讄上下文菜?br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span></div>  下面q有好多,可以Ҏ(gu)具体情况修改<br />4>jsp面使用:<br /> 拯一个例子就可以?<br /> 说明:oFCKeditor.setBasePath("FCKeditor/");q个路径的根据你的具体\径变?br />=====================<br />支持上传功能<br />1>d:commons-fileupload.jar<br />2>修改Web.xml 具体在FCKeditor.Java有例?br /> 说明:baseDir上传文g保存路径<br />      SimpleUploader下的 enabled 是否开启上传功?br />      <url-pattern> Ҏ(gu)具体应用q行修改<br />3>修改:fckconfig.js<br />  <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">FCKConfig.LinkBrowserURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser</span><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser.html</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Connector</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">connectors</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">jsp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">connector';<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> FCKConfig.ImageBrowserURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser</span><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser.html</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Image</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">Connector</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">connectors</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">jsp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">connector';<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> FCKConfig.FlashBrowserURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser</span><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">browser.html</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Flash</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">Connector</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Connector</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">connectors</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">jsp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">connector';<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> FCKConfig.LinkUploadURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">upload</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">simpleuploader</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">File';<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> FCKConfig.ImageUploadURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">upload</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">simpleuploader</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Image' ;<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> FCKConfig.FlashUploadURL </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> FCKConfig.BasePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> 'filemanager</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">upload</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">simpleuploader</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">Type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Flash' ;</span></div><br /> <br /> 说明:要和web.xml ?url-pattern 相对?Type=*** 要对?br /><br />完成!<img src ="http://www.aygfsteel.com/yidishui/aggbug/64121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yidishui/" target="_blank">一滴水</a> 2006-08-17 14:25 <a href="http://www.aygfsteel.com/yidishui/archive/2006/08/17/64121.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ibtis基本配置--[dibatis Dao支持]http://www.aygfsteel.com/yidishui/archive/2006/07/19/59024.html一滴水一滴水Wed, 19 Jul 2006 09:06:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/07/19/59024.htmlhttp://www.aygfsteel.com/yidishui/comments/59024.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/07/19/59024.html#Feedback0http://www.aygfsteel.com/yidishui/comments/commentRss/59024.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/59024.html阅读全文

一滴水 2006-07-19 17:06 发表评论
]]>
Ibatis基本配置---[环境搭徏]http://www.aygfsteel.com/yidishui/archive/2006/07/19/59021.html一滴水一滴水Wed, 19 Jul 2006 08:54:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/07/19/59021.htmlhttp://www.aygfsteel.com/yidishui/comments/59021.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/07/19/59021.html#Feedback4http://www.aygfsteel.com/yidishui/comments/commentRss/59021.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/59021.html阅读全文

一滴水 2006-07-19 16:54 发表评论
]]>
d资源文ghttp://www.aygfsteel.com/yidishui/archive/2006/07/18/58841.html一滴水一滴水Tue, 18 Jul 2006 12:17:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/07/18/58841.htmlhttp://www.aygfsteel.com/yidishui/comments/58841.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/07/18/58841.html#Feedback1http://www.aygfsteel.com/yidishui/comments/commentRss/58841.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/58841.html
driver=org.hsqldb.jdbcDriver
url=jdbc:hsqldb:mem:jpetstore
username=sa
password=

java代码
      Properties props = Resources.getResourceAsProperties("properties/database.properties");
      String url 
= props.getProperty("url");
      String driver 
= props.getProperty("driver");
      String username 
= props.getProperty("username");
      String password 
= props.getProperty("password");



一滴水 2006-07-18 20:17 发表评论
]]>
hibernate Hql 不支持中文问题!Q?/title><link>http://www.aygfsteel.com/yidishui/archive/2006/02/19/31532.html</link><dc:creator>一滴水</dc:creator><author>一滴水</author><pubDate>Sun, 19 Feb 2006 10:16:00 GMT</pubDate><guid>http://www.aygfsteel.com/yidishui/archive/2006/02/19/31532.html</guid><wfw:comment>http://www.aygfsteel.com/yidishui/comments/31532.html</wfw:comment><comments>http://www.aygfsteel.com/yidishui/archive/2006/02/19/31532.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yidishui/comments/commentRss/31532.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yidishui/services/trackbacks/31532.html</trackback:ping><description><![CDATA[<span id="wmqeeuq" class=postbody><FONT size=2>   hibernate3.0.2中执行如下的Q?<BR><SPAN style="FONT-WEIGHT: bold">from Persion p where p.name='张三'</SPAN>log信息,'张三'在这条hsql转成sql的时候变成了q<BR><BR>解决Ҏ(gu)Q升U到 Hibernate3.1 rc2 ! 只需要替?hibernate3.jar 文g可以了!</FONT></SPAN><img src ="http://www.aygfsteel.com/yidishui/aggbug/31532.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yidishui/" target="_blank">一滴水</a> 2006-02-19 18:16 <a href="http://www.aygfsteel.com/yidishui/archive/2006/02/19/31532.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POI问题记录http://www.aygfsteel.com/yidishui/archive/2006/02/15/30725.html一滴水一滴水Tue, 14 Feb 2006 17:51:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/02/15/30725.htmlhttp://www.aygfsteel.com/yidishui/comments/30725.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/02/15/30725.html#Feedback0http://www.aygfsteel.com/yidishui/comments/commentRss/30725.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/30725.html问题QHSSFSheet sheet1 = wb.createSheet("中文q");
旉Q?006-2-10
解决Ҏ(gu)Q?nbsp;    

HSSFSheet sheet = wb.createSheet();// 建立新的sheet对象
        wb.setSheetName(0"学生基本信息", (short1);

*********************************************



一滴水 2006-02-15 01:51 发表评论
]]>
jsf Hssf 创徏q下?M$ Excelhttp://www.aygfsteel.com/yidishui/archive/2006/01/21/28851.html一滴水一滴水Fri, 20 Jan 2006 18:29:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/01/21/28851.htmlhttp://www.aygfsteel.com/yidishui/comments/28851.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/01/21/28851.html#Feedback0http://www.aygfsteel.com/yidishui/comments/commentRss/28851.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/28851.html在jsf中通过FacesContext讉K上下文;
Hssf通过 HSSFWorkbook 向输出流写入Q?BR>具体代码Q?BR>
BeanQ?/P>
public class TestBean {
    
public String action() {
        HSSFWorkbook wb 
= new HSSFWorkbook();
        FacesContext context
=FacesContext.getCurrentInstance();
        HttpServletResponse response 
= (HttpServletResponse) context.getExternalContext().getResponse();
        response.reset();
        response.setContentType(
"application/ms-excel");
        
try {
            response.setHeader(
"Content-disposition""attachment;filename="+new String("下蝲Excel.xls".getBytes(),"iso-8859-1"));
            wb.write(response.getOutputStream());
        }
 catch (Exception e1) {
            
// TODO Auto-generated catch block
            e1.printStackTrace();
        }

        FacesContext.getCurrentInstance().responseComplete();
        
return null;
    }

}

以上只是一个空的简单的Excel 具体怎么创徏W合目要求的参看:(x)HSSF GUIDEQ?BR>faces-config.xml:
<managed-bean>
        
<managed-bean-name>test</managed-bean-name>
        
<managed-bean-class>yds.study.web.TestBean</managed-bean-class>
        
<managed-bean-scope>session</managed-bean-scope>
    
</managed-bean>
jspQ?BR>
<f:view>
    
<h:form>
        
<h:commandButton id="button" value="下蝲" rendered="true"
            action
="#{test123.action}" />
    
</h:form>
</f:view>

okq样可以了;)

一滴水 2006-01-21 02:29 发表评论
]]>
Jakata Poi HSSFQ纯Java的Excel解决Ҏ(gu) [zz]http://www.aygfsteel.com/yidishui/archive/2006/01/20/28776.html一滴水一滴水Fri, 20 Jan 2006 05:52:00 GMThttp://www.aygfsteel.com/yidishui/archive/2006/01/20/28776.htmlhttp://www.aygfsteel.com/yidishui/comments/28776.htmlhttp://www.aygfsteel.com/yidishui/archive/2006/01/20/28776.html#Feedback0http://www.aygfsteel.com/yidishui/comments/commentRss/28776.htmlhttp://www.aygfsteel.com/yidishui/services/trackbacks/28776.html
       在我们实际的开发中Q表现层的解x案虽然有多样Q但是IE览器已成ؓ(f)最多h使用的浏览器Q因为大安用Windows。在企业办公pȝ中,常常有客戯样子要求Q你要把我们的报表直接用Excel打开?BR>
或者是Q我们已l习(fn)惯用Excel打印。这样子如果?net开发是没有问题的,但是有J2EEq个?net更有前途的开攑ּ的开发环境,N我ؓ(f)了解x印的要求d写客L(fng)的控Ӟ或者在服务器端使用本地代码Q第一U方案的问题是关键数据的处理有时候不能在客户端做Q第2U方案的问题是牺牲了代码的可UL性和E_性。如果让客户端只负责处理生成好的报表Q那是一U诱人的选择?BR>
Apache的Jakata目的POI子项目,目标是处理ole2对象。目前比较成熟的是HSSF接口Q处理MS ExcelQ?7-2002Q对象。它不象我们仅仅是用csv生成的没有格式的可以由Excel转换的东西,而是真正的Excel对象Q你可以控制一些属性如sheet,cell{等?BR>
q是一个年ȝ目Q所以象HDFq样直接支持Word对象的好东西仍然在设计中。其它支持word格式的纯JavaҎ(gu)q有itextQ不q也是仍在奋斗中。但是HSSF已经成熟到能够和_我们使用了?BR>
其实Q从开发历史的角度Ԍ?0q代中期starOffice的原作者在德国成立了StarOffice suite公司Q然后到1999q夏天starOffice被sun收购Q再?000q?月starOffice5.2的发布;q且从starOffice6.0开始,starOffice建立在OpenOffice的api的基上,q个公开代码的office目已经q行了很长的旉。虽焉是由C++写的Q但是POI的代码部分也是由openOffice改过来的。所以,应该对POI充满_的信心。国内已l有部分公司在他们的办公自动化等Web目中用poi了,如日恒的iofficeQv泰的HTOffice{?BR>
Java当初把核心处理设成UnicodeQ带来的好处是另代码适应了多语言环境。然而由于老外的英语只?6个字母,有些情况下,一些程序员?位的byte处理Q一不小心就L了CJK的高位。或者是׃?fn)惯在程序中采用编码,q有多种原因Q得许多Java应用在CJK的处理上很烦(ch)恹{还好在POI HSSF中考虑到这个问题,可以讄encoding为双字节?BR>
POI可以到www.apache.org下蝲到。编译好的jar主要有这?个:(x)poi?poi Browser?poi hdf?poi hssf例程包。实际运行时Q需要有poi包就可以了?BR>
如果用Jakarta ant~译和运行,下蝲apache Jakarta POI的release中的src包,它里面已lؓ(f)你生成好了build文g了。只要运行ant可以了(ant 的安装和使用在此不说?。如果是用Jbuilder q行Q请在新建的目中加入poi包?BR>
以Jbuilder6ZQ选择Tools菜单的config libraries...选项Q新Z个lib。在弹出的菜单中选择poi包,如这个jakarta-poi-1.5.1-final-20020820.jarQ把poid到jbuilder中。然后,右键点击你的目Q在project的properties菜单中path的required Libraries中,点addQ添加刚才加入到jbuilder中的poiC现在的项目中?BR>
如果你仅仅是Z熟?zhn)POI hssf的用,可以直接看POI的samples包中的源代码Qƈ且运行它。hssf的各U对象都有例E的介绍。hssf提供的例E在org.apache.poi.hssf.usermodel.examples包中Q共?4个,生成的目标xls都是workbook.xls。如果你想看更多的例E,可以参考hssf的Junit test casesQ在poi的包的源代码中有。hssf都有试代码?BR>q里只对部分例程的实现做介绍?BR>
HSSF提供l用户用的对象在org.apache.poi.hssf.usermodel包中,主要部分包括Excell对象Q样式和格式Q还有辅助操作。有以下几种对象Q?BR>
HSSFWorkbook excell的文档对?BR>
HSSFSheet excell的表?BR>
HSSFRow excell的行

HSSFCell excell的格子单?BR>
HSSFFont excell字体

HSSFName 名称

HSSFDataFormat 日期格式

在poi1.7中才有以?:(x)

HSSFHeader sheet?BR>
HSSFFooter sheet?BR>
和这个样?BR>
HSSFCellStyle cell样式

辅助操作包括

HSSFDateUtil 日期

HSSFPrintSetup 打印

HSSFErrorConstants 错误信息?BR>
仔细看org.apache.poi.hssf包的l构Q不隑֏现HSSF的内部实现遵循的是MVC模型?BR>
q里我用Rose把org.apache.poi.hssf.usermodel包中的对象反向导入ƈҎ(gu)怺关系作了整理Q详见下面两图:(x)







? 基本对象



从中不难可以发现每一个基本对象都兌了一个Record对象。Record对象是一个参考Office格式的相兌录?nbsp;





? HSSFWorkbook



HSSFWorkbookx一个Excell对象。这q类图体现的是HSSFWorkbook和基本对象的怺关系。可见,许多对象中也建立了Workbook的引用。还需要注意的是在HSSFWorkbook和HSSFSheet中徏立了log机制POILoggerQ而且POILogger也是使用apache Log4J实现的?BR>
先看poi的examples包中提供的最单的例子Q徏立一个空xls文g?BR>

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
public class NewWorkbook
{
public static void main(String[] args)throws IOException
{
HSSFWorkbook wb 
= new HSSFWorkbook();
//建立新HSSFWorkbook对象
FileOutputStream fileOut =
new FileOutputStream("workbook.xls"Q?
wb.write(fileOut);
//把Workbook对象输出到文件workbook.xls?/SPAN>
fileOut.close();
}

}





通过q个例子Q我们徏立的是一个空白的xls文gQ不是空文gQ。在此基上,我们可以q一步看其它的例子?nbsp;


import org.apache.poi.hssf.usermodel.*;

import java.io.FileOutputStream;

import java.io.IOException;

public class CreateCells

{

public static void main(String[] args)

throws IOException

{

HSSFWorkbook wb 
= new HSSFWorkbook();
//建立新HSSFWorkbook对象

HSSFSheet sheet 
= wb.createSheet("new sheet"Q?
//建立新的sheet对象


// Create a row and put some cells in it.
Rows are 0 based.

HSSFRow row 
= sheet.createRow((short)0);
//建立新行

// Create a cell and put a value in it.

HSSFCell cell 
= row.createCell((short)0);
//建立新cell

cell.setCellvalue(
1);//讄cell的整数类型的?BR>

// Or do it on one line.

row.createCell((
short)1).setCellvalue(1.2);
//讄cell点cd的?/SPAN>

row.createCell((
short)2).setCellvalue("test"Q?
//讄cell字符cd的?/SPAN>

row.createCell((
short)3).setCellvalue(true);
//讄cell布尔cd的?nbsp;

HSSFCellStyle cellStyle 
= wb.createCellStyle();
//建立新的cell样式

cellStyle.setDataFormat
(HSSFDataFormat.getFormat(
"m/d/yy h:mm"Q);
//讄cell样式为定制的日期格式

HSSFCell dCell 
=row.createCell((short)4);

dCell.setCellvalue(
new Date());
//讄cell为日期类型的?/SPAN>

dCell.setCellStyle(cellStyle); 
//讄该cell日期的显C格?/SPAN>

HSSFCell csCell 
=row.createCell((short)5);

csCell.setEncoding(HSSFCell.ENCODING_UTF_16);
//讄cell~码解决中文高位字节截断

csCell.setCellvalue(
"中文试_Chinese Words Test"Q?
//讄中西文结合字W串

row.createCell((
short)6).setCellType
(HSSFCell.CELL_TYPE_ERROR);
//建立错误cell


// Write the output to a file

FileOutputStream fileOut 
= 
new FileOutputStream("workbook.xls"Q?

wb.write(fileOut);

fileOut.close();

}


}





我稍微修改了原来的examples包中的CreateCellscd了上面的功能试cR通过q个例子Q我们可以清楚的看到xls文g从大到小包括了HSSFWorkbook HSSFSheet HSSFRow HSSFCellq样几个对象。我们可以在cell中设|各U类型的倹{?nbsp;

其要注意的是如果你x的昄非欧的字符Ӟ其象中日韩q样的语aQ必设|编码ؓ(f)16位的xHSSFCell.ENCODING_UTF_16Q才能保证字W的?位不被截断而引L(fng)码失真Ş成ؕ码?nbsp;

其他试可以通过参考examples包中的测试例子掌握poi的详l用法,包括字体的设|,cell大小和低U的讄{。需要注意的是POI是一个仍然在完善中的公开代码的项目,所以有些功能正在不断的扩充?nbsp;

如HSSFSheet的getFooter() getHeader()和setFooter(HSSFFooter hsf) setHeader(HSSFHeader hsh)是在POI1.7中才有的Q而POI1.5中就没有。运行测试熟(zhn)代码或者用它做项目时h意POI的版本?nbsp;

另外需要注意的是HSSF也有它的对xlsZ事g的解析。可以参考例E中的EventExample.java。它通过实现HSSFListener完成从普通流认知Xls中包含的内容Q在apache Cocoon中的org.apache.cocoon.serialization.HSSFSerializer中用Cq个解析。因为Cocoon2是基于事件的Q所以POIZ提供快速的解析也提供了相应的事件。当然我们自׃可以实现q个事g接口?nbsp;

因ؓ(f)POIq不是一个够成熟的目Q所以有必要做进一步的开发和试。但是它已经为我们用UJava操作ole2对象提供了可能,而且克服了ole对象调用的缺P提供了服务器端的Excel解决Ҏ(gu)?BR>

一滴水 2006-01-20 13:52 发表评论
]]>
վ֩ģ壺 | ˮ| | | ƽ| Ϫ| | | | | Ҿ| Ϫ| ̶| | | Ӫɽ| | ƽ| | | ɽ| | ƽɽ| | ˶| | | | Ȫ| | ˮ| ˮ| | | ܱ| Ͷ| Ҷ| | | | |