我们写代码一定要遵守代码规范,完善文档

  文档现在在我的心里越来越重要,学习日记不完善的文档成了我心里的一个疙瘩,文档不完善,学习日记的继续向前发展将岌岌可危。主要是:

  1、大家难以交流;

  2、设计思路没有整理,有的代码实现日后再看将是一头雾水,成为向前的羁绊。

  不管是否立刻开始新系统的设计,还是继续完善学习日记现有的一些网友早就提出的紧要问题,把学习日记的文档完善成了一个很大的挑战摆在了我的眼前。

  怎么办?To be or not to be?

mysql数据库的导出和导入

  用图形工具是比较方便的,比如我用的:SQLyog。

  在命令行中的方式为:

  1、把整个数据库导出为一个sql文件:用:mysqldump dbname > c:\mydb.sql

  2、把sql文件导入数据库:用mysql命令进入mysql,在mysql>提示符下输入:

  1)创建数据库:create database newdb;

  2)使用当前数据库:use newdb;

  3)导入sql文件中的数据:source c:\mydb.sql(无分号)

  这样,就把mydb.sql中的数据导入到新的数据库newdb了。

学习日记V0.9.0.4正式推出!

  学习日记V0.9.0.4正式推出!下载地址:http://www.learndiary.com/download/learndiaryV0.9.0.4.war。在learndiaryV0.9.0.3的基础上,有如下主要的变化:

  1)、完善网站的动态导航系统;

  2)、根据功能拆分原来的数据库存取对象,但这不是一个真正的DAO方案;

  3)、初步改善登录模式;

  4)、数据库改为utf-8编码,你可以用任意语言书写自己的学习日记;

  5)、修复了一些bug。

  最新的源代码在我们开发社区的CVS库中随时更新(地址:http://learndiary.tigris.org/source/browse/learndiary/old)。欢迎有志于开源事业的Java爱好者加入到我们的开发队伍。

  我们将本着应用为先,用户至上的原则继续向前发展,为最终实现建设一个具有普遍适用性的开源网络学习交流平台而努力。

struts国际化问题(转贴,如有侵权,请告知)

放在这里备忘。

>> 欢迎您,客人: 登录 | 注册 | 忘记密码 | 在线 | 搜索 | 帮助    |  

 

论坛全文检索:    

 

  【ChinaJavaWorld.com技术论坛】

 『 Struts 及 MVC Framework论坛 』   [返回]

   [原创]"struts中文问题&quo ...  

标记论坛所有内容为已读  

>> 『 Struts 及 MVC Framework论坛 』  欢迎您的到来 << 

    ◆您是本帖第 257 个阅读者◆        

 

  * 贴子主题: [原创]"struts中文问题","struts国际化问题"——终极解决方案                 

 

 

  baozitou007     

 

 

信息:    

威望: 0

来自: 湖北鄂州 

总发贴数: 35 篇

注册日期: 2004/01/17

 

 消息 查看 搜索 好友 邮件 QQ 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  引文

----------------------------------------

----------------------------------------

说实话,你们的方法都做的复杂了,Java本身就支持多国语言编码,不需要写任何程序,可以很简单的

实现。

秘诀就是两点:

1、所有HTML/JSP页面全部采用UTF-8编码

2、客户端浏览器完全支持UTF-8编码

步骤:

1、首先把所有的HTML/JSP的ContentType都设为UTF-8

2、然后对于JSP程序中的非ASCII码提示信息都不应该写在程序里面,都应该放在

application.properties里面统一管理。

3、对HTML用native2ascii工具统一做一次处理,把HTML中的非ASCII码都转换为Unicode编码。

4、针对不同的语言,写不同的application.properties,比如说简体中文是

application_zh_CN.properties,繁体中文是application_zh_TW.properties这样,然后对这些配置信

息文件同样用native2ascii工具处理一次,把非ASCII码统统转为Unicode编码。

5、在Servlet的request.getCharacterEncoding()获得客户端的操作系统默认编码,然后set到Struts

的HTTPSession的Locale中。

OK!现在不同的客户访问,就会显示不同的语言版本了。你可以看看此时你的浏览器的字符集,就是

UTF-8。现在你的网站和Google一样了,嘿嘿,其实你有心的话,看看你的浏览器访问Google的时候是

什么字符集吧

切记:所有的HTML/JSP都要设为UTF-8编码,所有的文件中的非ASCII码字符都要用native2ascii工具转

为用ASCII表示的Unicode编码。

----------------------------------------

----------------------------------------

原创

----------------------------------------

上面所述是我从网上下的一篇于中文问题的解决方案,确切的说应该是关于Struts的国际化问题,下面我结合我的实践谈谈具体如何实现Struts的国际化问题,我对理论不是非常精通,我只能完全凭自己的理解和实践来讲述,所以下面讲的内容可能不是非常正确,还请大家原谅。但有一点可以肯定,我通过自己的努力解决了Struts的中文问题,并实现Struts的国际化,其实一切并不复杂,下面是具体步骤:

  0.遇到的问题(这些问题也许不会同时出现)

    a.中文数据从数据库中到jsp中后就变成了"????"

    b.做好的中文properties文件,其中的中文value在页面显示乱码

    c.jsp文件中的中文到浏览器后显示时也是乱码(建议不要在jsp文件中输入中文,尽量放在properties文件中)

    d.由jsp传给bean的中文值,再由bean传回页面又是乱码

    e.当更换本地浏览器的语言选项时,Web应用程序不能自动根据你的locale选择合适的*.properties文件。导致Web应用程序不能国际化。

  1.环境:

      Web服务器: Tomcat 5.0.19

       操作系统: Win2000 Server

         JVM   : jdk 1.4

       数 据 库: Oracle 8.1.7

       开发工具: struts studio 5.2 pro   for  eclipse

  2.先将所有*.jsp 网页中开头处加入

    <%@ page language="java" contentType="text/html; charset=utf-8" %>

     再设置<html:html locale = "true">

  3.然后编辑好两个*.properties文件,放在classes文件夹下你指定的地方,这里是放在/web-inf/classes/com/wiley 下,它们分别是:

    ApplicationResources.properties  (英文资源文件)

    ApplicationResources_zh.properties (中文资源文件)

    随便用什么工具编写都行啊!

  4.将ApplicationResources_zh.properties转码成gb2312。上面引文说要转成UTF-8,结果我试了,不行。转成gb2312就行了,操作是。

    将ApplicationResources_zh.properties更名为ApplicationResources_xx.properties

    在DOS命令行进入ApplicationResources_xx.properties所在的文件夹

    使用命令:native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties(至于你为什么会出现“native2ascii不是内部命令”,,请查其它资料,可能你要设置环境变量,因为他是jdk的文件夹bin下的一个应用程序)

   5.接下来配置struts-config.xml,很简单,我们加入:

   <message-resources parameter="com.wiley.ApplicationResources"/>  就行了;

   到此已能解决大多数中文问题。如上面所说的a,b,e 现在打开浏览器,选择菜单:工具》internet选项》语言,将“中文-中国[zh-cn]”删掉,添加一个“英语-英国[zh-gb]”确定后,重启Tomcat,输入网址你就会发现,你的页面的文本信息就会用的是ApplicationResources.properties  (英文资源文件)中的内容。如果换回“中文-中国[zh-cn]”,它就会显示ApplicationResources_zh.properties (中文资源文件)中的中文内容。

  至于问题“c.jsp文件中的中文到浏览器后显示时也是乱码” 你就要用与第4步类似的方法来重新对*.jsp 文件编码,这时-encoding的参数就要用UTF-8了,如果你用的也是struts studio 5.2 pro   for  eclipse工具,这一步就免了。它会自动用UTF-8的格式存储。

  至于问题“d.由jsp传给bean的中文值,再由bean传回页面又是乱码”的解决,我只是加了个过滤器。

你可以现在web.xml中加入:

<filter>

<filter-name>Set Character Encoding</filter-name>

<filter-class>com.wiley.SetCharacterEncodingFilter</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>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>Set Character Encoding</filter-name>

<servlet-name>action</servlet-name>

</filter-mapping>

  然后在你指定的包内加个java文件 我放在了/web-inf/classes/com/wiley 里,下面是源代码:

/*

* XP Forum

*

* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.

*

*/

package com.huahang.tj.struts.filters;

import javax.servlet.*;

import java.io.IOException;

/**

* <p>Filter that sets the character encoding to be used in parsing the

* incoming request, either unconditionally or only if the client did not

* specify a character encoding. Configuration of this filter is based on

* the following initialization parameters:</p>

* <ul>

* <li><strong>encoding</strong> - The character encoding to be configured

* for this request, either conditionally or unconditionally based on

* the <code>ignore</code> initialization parameter. This parameter

* is required, so there is no default.</li>

* <li><strong>ignore</strong> - If set to "true", any character encoding

* specified by the client is ignored, and the value returned by the

* <code>selectEncoding()</code> method is set. If set to "false,

* <code>selectEncoding()</code> is called <strong>only</strong> if the

* client has not already specified an encoding. By default, this

* parameter is set to "true".</li>

* </ul>

*

* <p>Although this filter can be used unchanged, it is also easy to

* subclass it and make the <code>selectEncoding()</code> method more

* intelligent about what encoding to choose, based on characteristics of

* the incoming request (such as the values of the <code>Accept-Language</code>

* and <code>User-Agent</code> headers, or a value stashed in the current

* user's session.</p>

*

* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>

*

* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $

*/

public class SetCharacterEncodingFilter implements Filter {

// ----------------------------------------------------- Instance Variables

/**

* 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 result The servlet response we are creating

* @param chain The filter chain we are processing

*

* @exception IOException if an input/output error occurs

* @exception 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

*/

protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}

}//EOC

   到此我遇到的中文问题已全部得到解决,并从中理解到struts的国际化的深刻含义。

我个人觉得struts作为一个功能强大的应用框架,应该早就考虑到它的国际化问题,并在实际应用中不会很复杂,只要我们遵循一些规则,就可以尽情享受struts给我们带来的无穷乐趣。希望以上所述对大家有所帮助。

 

 

 

 

--------------------------------------------------------------------------------

  2004/03/30 09:36am IP: 已设置保密  

 

 

 

  风行天下     

 

 

信息:    

威望: 0

来自: 北京 

总发贴数: 59 篇

注册日期: 2003/04/28

 

 消息 查看 搜索 好友 邮件 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  thanks very much

 

 

 

--------------------------------------------------------------------------------

  2004/03/30 12:07pm IP: 已设置保密  

 

 

 

  zhushilin     

  kopf43

 

信息:   

威望: 0

来自: 上海 

总发贴数: 43 篇

注册日期: 2002/07/24

 

 消息 查看 搜索 好友 邮件 QQ 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  好文章,长见识了

 

 

 

--------------------------------------------------------------------------------

  2004/03/30 01:17pm IP: 已设置保密  

 

 

 

  iamisabird     

 

 

信息:  

威望: 0

来自: 保密 

总发贴数: 17 篇

注册日期: 2004/02/21

 

 消息 查看 搜索 好友 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  我想问一下,在步骤2中提到的“非ASCII码提示信息“是指哪些东西

 

 

 

--------------------------------------------------------------------------------

  2004/03/30 11:36pm IP: 已设置保密  

 

 

 

  baozitou007     

 

 

信息:    

威望: 0

来自: 湖北鄂州 

总发贴数: 35 篇

注册日期: 2004/01/17

 

 消息 查看 搜索 好友 邮件 QQ 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  这里说的“非ASCII码提示信息”说的是在你的jsp文件中输入不是a,b,c,d......r等ASCII码表中的字符,比如说“中文”,或者是“韩文”等,这都是非“非ASCII码提示信息”例如:

    <html:html xhtml="true" locale="true">

<head>

   <title>

      <bean:message key="app.title" />

   </title>

</head>

<body>

    看来UTF-8是个好东西!

<table width="500" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td> </td>

  </tr>

  <tr bgcolor="#36566E">

    <td height="68" width="48%">

----------------------------------

其中“看来UTF-8是个好东西!”就是我们说的“非ASCII码提示信息”

 

 

 

--------------------------------------------------------------------------------

  2004/03/31 09:19am IP: 已设置保密  

 

 

 

  momocha     

 

 

信息: 

威望: 0

来自: 保密 

总发贴数: 59 篇

注册日期: 2003/06/26

 

 消息 查看 搜索 好友 邮件 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  切记:所有的HTML/JSP都要设为UTF-8编码,所有的文件中的非ASCII码字符都要用native2ascii工具转

为用ASCII表示的Unicode编码。

问个问题,你所说的这一步不太明白,是不是每一个包含非ascii的jsp/html文件都要用这个工具转换一个,能说说这个工具吗,谢谢了!!

 

 

 

 

--------------------------------------------------------------------------------

  2004/03/31 03:03pm IP: 已设置保密  

 

 

 

  baozitou007     

 

 

信息:    

威望: 0

来自: 湖北鄂州 

总发贴数: 35 篇

注册日期: 2004/01/17

 

 消息 查看 搜索 好友 邮件 QQ 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  native2ascii -encoding gb2312 jspname.jsp newjspname.jsp

  native2ascii这个工具是jdk自带的一个东东,所以如果path都设定正确就可以直接运行了,你可以在$java_home$/bin下找到他。

  所以你要设一下系统环境变量:C:\jdk\bin

 

 

 

 

--------------------------------------------------------------------------------

  2004/04/01 10:01am IP: 已设置保密  

 

 

 

  sdyjmc   头衔: 飞天

 

 

信息:   

威望: 0

来自: 其它大洋洲 

总发贴数: 886 篇

注册日期: 2001/12/21

 

 消息 查看 搜索 好友 主页 QQ ICQ 复制 引用 回复   加到"个人收藏夹"

--------------------------------------------------------------------------------

  不知数据库中的编码,在datasource中怎么解决?能够建立pool的时候指定编码?

<set-property property="weblogic.codeset" value="GBK" />

 

 

 

 

--------------------------------------------------------------------------------

  2004/04/01 04:54pm IP: 已设置保密  

 

 

 

 该主题只有一页  跳转论坛至... ╋Java 2 Platform, Standard Edition (J2SE) 与Java核心技术论坛 |-『 Java语言*初级版 』 |-『 Java语言*高级版 』 |-『 JavaGUI设计 』 |-『 Java安全版块 』 |-『 Java工具安装、配置与使用 』 |-『 Java新技术,新闻,应用与资源等 』╋Java 2 Platform, Enterprise Edition (J2EE) 技术论坛 |-『 JSP/Servlets/JSF 』 |-『 JDBC,JDO 』 |-『 EJB 』 |-『 其他J2EE技术 』╋Java 2 Platform, Micro Edition (J2ME)技术论坛 |-『 J2ME 技术论坛 』╋J2EE 应用服务器 技术论坛 |- 『 BEA WebLogic Platform 技术论坛 』 |-『 IBM WebSphere 技术论坛』 |-『 其他应用服务器技术论坛 』  ╋Web Services和XML技术 |-『 Web Services 技术论坛 』 |-『 XML技术论坛 』╋Apache Jakarta Project技术论坛 |-『 Tomcat技术论坛』   |-『 Struts 及 MVC Framework论坛 』  ╋软件过程管理,建模等 |-『 设计模式 』 |-『 UML 』 |-『 软件测试 』 |-『 软件工程,过程及项目管理 』╋Java相关认证论坛系列 |-『 SCJP认证论坛 』 |-『 Java其他认证 』╋数据库技术 |-『 Oracle&PostgreSQL技术论坛 』╋其他软件开发技术 |-『 C#和.Net技术论坛 』╋操作系统 |-『 操作系统论坛 』╋其他 |-『 休闲乐园 』 |-『 英语学习论坛 』 |-『 求职与招聘 』 |-『 广告论坛 』╋站务建设区 |-『 站务建设 』 |-『 版主专区 』   |-『 论坛公告区 』 |-『 帖子讨论专区 』╋ChinaJavaWorld服务专栏 

   快速回复主题: [原创]"struts中文问题","struts国际化问题"——终极解决方案

输入用户名和密码: 用户名:  没有注册? 密码:  忘记密码?

上传附件或图片 (最大容量 300KB)   支持类型:----------gifjpgbmpzippngswfdoctxthtmhtmlgzrartarsxw

选项

使用 LB5000 标签?

显示您的签名?

有回复时使用邮件通知您?

 

   [使用 Ctrl+Enter 直接提交贴子] 

 

 顶端 加到"个人收藏夹" 主题管理: 总固顶 | 取消总固顶 | 区固顶 | 取消区固顶 | 固顶 | 取消固顶 |

精华 | 取消精华 | 提升 | 锁定 | 解锁 | 删除 | 删除回复 | 移动 | 

  

--------------------------------------------------------------------------------

© 中文版权所有: Java开发者  版本: LB5000MX 2.00

程序版权所有: CGI 编程者之家    程序编制: 山鹰(糊)、 花无缺

本论坛言论纯属发表者个人意见,与 【ChinaJavaWorld.com技术论坛】 立场无关

 

基础问题出错:String的split(String str)方法用法

  如果一行只有一个回车换行符,那么这行用这个方法分开得到是一个0长度字符串,

下面这一句:

        if (charArray[0] != ' ') {

        sB.append(lineStr);

        sB.append("<br>");

      }

  就会出现indexOutOfBoundary这样的错误。

    //replace space at beginning and add "<br>" at end of every line

    String[] strArray = tempStr.split("\n");

    StringBuffer sB = new StringBuffer();

    for (int i = 0; i < strArray.length; i++) {

      String lineStr = strArray[i];

      //System.out.println(i +" : lineStr is: " + lineStr+"ok");

      char[] charArray = lineStr.toCharArray();

 

      //if no any char in this line,then add a <br> to the end of sB,

      //continue loop(don't excute the code behind continue in this loop).

      if (charArray.length == 0){

        sB.append("<br>");

        //System.out.println("come here.");

        continue;

      } 

     

      if (charArray[0] != ' ') {

        sB.append(lineStr);

        sB.append("<br>");

      }

完整代码:

package com.learndiary.website.util;

//import com.learndiary.util.*;

public class Util {

   

  public static String htmlFormat(String source) {

    //if (source==null) return null;//WHEN the source is "",run at line 33,will happen ArrayIndexOutOfBoundsException.

    //because char[0] don't exist a charactor.

    if ((source==null)||(source.length()==0)) return "";

    //replace "<>"

    String tempStr = source.replaceAll("<", "<").replaceAll(">", ">");

   

    //replace space at beginning and add "<br>" at end of every line

    String[] strArray = tempStr.split("\n");

    StringBuffer sB = new StringBuffer();

    for (int i = 0; i < strArray.length; i++) {

      String lineStr = strArray[i];

      //System.out.println(i +" : lineStr is: " + lineStr+"ok");

      char[] charArray = lineStr.toCharArray();

 

      //if no any char in this line,then add a <br> to the end of sB,

      //continue loop(don't excute the code behind continue in this loop).

      if (charArray.length == 0){

        sB.append("<br>");

        //System.out.println("come here.");

        continue;

      } 

     

      if (charArray[0] != ' ') {

        sB.append(lineStr);

        sB.append("<br>");

      } else {

      for (int j = 0; j < charArray.length; j++) {//if the first char of this String is space,need convert the first space to " "

        if (charArray[j] == ' ')//if there are several spaces at the begin of this String,need convert every space to " ".

          sB.append(" ");  

          else {//once meet a char isn't a space,then every space after this char needn't to be converted to " " in this string.

                //we can add the all charaters after this char,then ,add "<br>" to the end of this String.

            sB.append(charArray, j, charArray.length - j);

            //sB.append("<br>");

            break;

          }

        }

        sB.append("<br>");//need add " " to the end of this string.why put this sentence at here?

                          //if every character is space in this string,it also needs adding "<br>" at the end of this string.

      }

    }

   

    String resultTemp = sB.toString();

    String result = resultTemp.substring(0, resultTemp.length() - 4);       

    return result;

    //replaceAll(" ", " ").

  } 

 

  // Simple test:

  /* 

  public static void main(String[] args) throws Exception {

    String file = TextFile.read("gb5.txt");

    System.out.println("file is: \n" + file);

    String result = htmlFormat(file);

    System.out.println("result is \n" + result);

    write("test.txt", file);

    TextFile text = new TextFile("test.txt");

    text.write("test2.txt");

  }

   */

}

jdk1.4的文档:(还没有看懂,记在这里,慢慢看)

split

public String[] split(String regex,

                      int limit)

Splits this string around matches of the given regular expression.

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

The string "boo:and:foo", for example, yields the following results with these parameters:

Regex Limit Result

: 2 { "boo", "and:foo" }

: 5 { "boo", "and", "foo" }

: -2 { "boo", "and", "foo" }

o 5 { "b", "", ":and:f", "", "" }

o -2 { "b", "", ":and:f", "", "" }

o 0 { "b", "", ":and:f" }

An invocation of this method of the form str.split(regex, n) yields the same result as the expression

Pattern.compile(regex).split(str, n)

Parameters:

regex - the delimiting regular expression

limit - the result threshold, as described above

Returns:

the array of strings computed by splitting this string around matches of the given regular expression

Throws:

PatternSyntaxException - if the regular expression's syntax is invalid

Since:

1.4

See Also:

Pattern

--------------------------------------------------------------------------------

split

public String[] split(String regex)

Splits this string around matches of the given regular expression.

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

The string "boo:and:foo", for example, yields the following results with these expressions:

Regex Result

: { "boo", "and", "foo" }

o { "b", "", ":and:f" }

Parameters:

regex - the delimiting regular expression

Returns:

the array of strings computed by splitting this string around matches of the given regular expression

Throws:

PatternSyntaxException - if the regular expression's syntax is invalid

Since:

1.4

See Also:

Pattern

改變學習日記的字符集總結,查詢utf數據庫?

版权声明:本文章为学习日记网站(http://www.learndiary.com )版权所有,以<a href="http://creativecommons.org/licenses/by/2.0/">Creative Commons License</a>方式授权。欢迎转载,但请注明文章原始出处(http://www.learndiary.com/disDiaryContentAction.do?goalID=1242 )。

 

  1、想在学习日记中(http://www.learndiary.com)贴繁体字的文章,结果是乱码;

  2、先改为GBK,可是不知道为什么,用GBK写到数据库中和页面上的字符都自动加了转义符了(\),如:(")变成了 (\"),还有,原来,文本里的回车换行都被加上了转义,于是,在网页上连换行都不行了,如:(\r\n)自动变成了(\\r\\n)。到现在,我也不知道这是什么原因,先放在这里,等以后再学习;

  3、看了jive3论坛,发现程序使用的字符集与mysql使用的默认字符集好像是无关的(究竟有没有关,还须进一步学习:),学习日记虚拟主机空间默认使用的是gb2312;于是,试着在数据库连接字符串用utf-8的characterEncoding=UTF-8;结果成功可以使用;

  4、原来数据库中的数据是gb2312编码的,必须转成utf-8。我用了一个笨办法,先把数据中的数据导出成sql文件,把sql文件全部用ultraedit(旧版本的不行,我下了一个最新的 11烈火版)转成utf-8格式;

  5、但是把转换后的sql文件重新导入数据库中出错,不知道为什么,偶然发现在用ultraedit转成的sql文件中的两个字段间缺了一个单引号',前一个字段后有一个?号,像:本该是这样的('学习','日记'),变成了('学?,'日记'),我想这是转码过程中出现的问题,问题是怎么一回事?现在还不清楚,以后学习;

  6、用ultraedit查找替换掉错误的地方,导入成功;

  7、导入后的数据有的被截掉了尾巴,原来是在utf-8编码中,一个汉字是3个字节,一个英文字符是1个字节,于是,原来的数据库字段长就不合适了;

  8、修改字段长度,然后把sql文件像上面那样转码、修改、导入。

  9、完成,可以用繁体字写日记了。

  10、缺陷:无法在数据库中直接用中文关键字执行查询了,也不能直接看到数据库中的内容了,不知道怎么解决这个问题?以后再学习。

的用法

忘性真大,一段時間不用,這些簡單的東西又要翻書了,看來,3天不用手生,3天不說口生。的確不假呀。

<html:text>和<html:textarea>标记分别HTML文本框和文本区,属性如下:

属性 描述

Property 定义当表单被提交时送回到服务器的请求参数的名称,或用来确定文本元素当前值的bean的属性名称

Name 属性被查询的bean的名称,它决定了文本框和文本区的值。如果没有设置,将使用与这个内嵌表单相关的ActionForm的名称

<html:text>标记还有以下属性:

属性 描述

Maxlength 能够输入的最大字符数

Size 文本框的大小(字符数)

(补充:这里的字符数是不论是汉字还英文,一个汉字和一个英文字符都算一个字符;与UTF-8对比为:一个汉字3个英文字符;与java中的对比:一个汉字1个英文;与gb2312对比:一个汉字2个英文字符(即2个字节))

例如:<html:text property="articleName" maxlength="50" size="50"/>

关于未来学习日记建立自己框架的设想

  看jive论坛,突然想到为了实现学习日记的宗旨,我们应该拥有一个服务于这一个宗旨的框架的支持。

  1、立足于网络学习领域;

  2、内核的网络性,像linux区别于传统windows;

  3、开放体系;

  4、名字嘛,想起一个:LearnMan。

  笑看斗转星移,岁月如歌,浩瀚宇宙,如一撮清波在我手中荡漾。

  框架很深奥吗?我不过认为那只是指甲里无意中发现的一粒亮尘。

尝试把数据库连接字符串改为characterEncoding=GBk

   学习日记不支持繁体,尝试把characterEncoding=GB2312改为GBK,繁体字倒是能显示了。但是,不知道为什么,java里的String.repalceAll()不能把繁体正文里面的\r\n替换成我需要的<br>,也就是说,它根本就没有发现里面有回车换行符。所以,这时,页面不能正确的换行。这个问题不是最紧要的,先把它记在这里,以后解决。