﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-持之以恒</title><link>http://www.blogjava.net/baizhihui19870626/</link><description>记录本</description><language>zh-cn</language><lastBuildDate>Tue, 12 May 2026 08:59:57 GMT</lastBuildDate><pubDate>Tue, 12 May 2026 08:59:57 GMT</pubDate><ttl>60</ttl><item><title>excel单元格拆分（原创）</title><link>http://www.blogjava.net/baizhihui19870626/articles/390800.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Mon, 05 Nov 2012 04:02:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/390800.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/390800.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/390800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/390800.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/390800.html</trackback:ping><description><![CDATA[<img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/baizhihui19870626/1.jpg" width="316" longdesc="" height="180" /><br />如图：将单元格1右边的单元格拆分成两个或更多，请按照如下步骤操作。<br />1、插入一行<br /><img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/baizhihui19870626/2.jpg" width="392" longdesc="" height="221" /><br /><img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/baizhihui19870626/3.jpg" width="329" longdesc="" height="144" /><br />2、将单元格1和下面的单元格进行合并<br /><img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/baizhihui19870626/4.jpg" width="635" longdesc="" height="193" /><br /><br /><br />效果：<br /><img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/baizhihui19870626/5.jpg" width="338" longdesc="" height="167" /><br /><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/390800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-11-05 12:02 <a href="http://www.blogjava.net/baizhihui19870626/articles/390800.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA SOAP技术(转http://www.cnblogs.com/mingzi/archive/2009/03/23/1419385.html)</title><link>http://www.blogjava.net/baizhihui19870626/articles/389671.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Tue, 16 Oct 2012 08:41:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/389671.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/389671.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/389671.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/389671.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/389671.html</trackback:ping><description><![CDATA[<font size="4">开始之前，我想就本文即将讨论的主题和读者需要具备的起点知识做一些必需的描叙。本文的主题是讨论SOAP技术，我们将尽可能的讲得通俗易懂一些，所以，我们引入了一个普通的&#8220;Hello World&#8221;范例来给读者说明它们是怎么运作的，让读者知道它们的运作方式。我认为，如果光看官方文档是很难开始学习这门新技术的，官方文档中包含大量的范例，并解释了所有的特性和优点，但是没解释它们的运作方式。在这篇文章中，我不打算只肤浅的解释SOAP技术的定义，我们假设读者熟悉JAVA语言，</font><a href="http://dev.21tx.com/web/" target="_blank"><font size="4"><span style="color: rgb(51,102,204)">Web</span> </font></a><font size="4">技术，具有</font><a href="http://dev.21tx.com/web/xml/" target="_blank"><font size="4"><span style="color: rgb(51,102,204)">XML</span> </font></a><font size="4">语言，XML Namespaces，XML Schema的基础。在这种情况下，理解本文将不存在任何困难。然而，即使没有这些知识，你也不必担心，我们将尽可能的解释得简单，但是当你开始做自己的 SOAP应用程序时会遇到一些问题和麻烦。因此，花费一定时间来学习上面的知识是很有必要的。</font> 
<p><span style="font-size: medium">从技术的角度来说，有必要提一下我们的调试环境。我们使用的是<a href="http://dev.21tx.com/os/windows/" target="_blank"><span style="color: rgb(51,102,204)">Windows</span> </a>XP<a href="http://dev.21tx.com/os/" target="_blank"><span style="color: rgb(51,102,204)">操作系统</span> </a>，安装有JAVA 2 SDK 1.4.1，Apache SOAP 2.3.1，JAF 1.0.2，<a href="http://dev.21tx.com/java/adv/javamail/" target="_blank"><span style="color: rgb(51,102,204)">JavaMail</span> </a>1.3.1和Xerces 2.6.0。上面所提及的都能在Tcomcat 4.1.29 <a href="http://dev.21tx.com/java/jsp/" target="_blank"><span style="color: rgb(51,102,204)">JSP</span> </a>/<a href="http://dev.21tx.com/java/jsp/" target="_blank"><span style="color: rgb(51,102,204)">Servlet</span> </a>容器中正常运行。所有的软件都是免费自由软件，因此你能够很容易的<a href="http://dl.21tx.com/" target="_blank"><span style="color: rgb(51,102,204)">下载</span> </a>它们并自己在任何你喜欢的平台如Windows或UNIX上安装它们。Java SDK，JAF和JAVAMAIL位于SUN的官方网站（</span> <a href="http://java.sun.com/"><span style="color: rgb(51,102,204); font-size: medium">http://java.sun.com</span> </a><span style="font-size: medium">），其他的软件在Jakarta项目组的官方网站（</span> <a href="http://jakarta.apache.org/"><span style="color: rgb(51,102,204); font-size: medium">http://jakarta.apache.org</span> </a><span style="font-size: medium">）上有down的。可能你在看到我们需要这么多不同的包（package）时已经有点担心和不安了，但是实际上你不应该担心这些的。一旦你懂了基础，那么对你将相当容易。安装不是一件很难的事情，你只需要在设置环境变量的时候仔细些，比如<em>CATALINA_HOME</em> , <em>CLASSPATH</em> , <em>JAVA_HOME </em>等等，所有这些步骤都是手工的。由于我仅仅是想将你的注意力再次集中到它们身上，所以你能很快的就完成以上配置过程。我只是添加下面的一些字符串到Tomcat的<em>bin/setclasspath.bat</em> 文件中：</span> </p><pre><span style="font-size: medium">...
set CATALINA_HOME=C:\Tomcat4.1.29
set CLASSPATH=%JAVA_HOME%\lib\tools.jar
set CLASSPATH=%JAVA_HOME%\soap-2.3.1\lib\soap.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\javamail-1.3.1\mail.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\jaf-1.0.2\activation.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xercesImpl.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xercesSamples.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xml-apis.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xmlParserAPIs.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\common\lib\servlet.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\common\lib\tools.jar
...
</span>
</pre>
<p><span style="font-size: medium">如果你的安装路径（installation paths）和上面使用的不同，你需要更正它们，然后关闭和重启Tomcat以使它们生效。这样，你就有为运行SOAP作好了准备。但是现在，我要忘记有关的技术部分，来学一点理论知识。</span> </p>
<p><span style="font-size: medium">SOAP意思是简单对象访问协议（<span style="text-decoration: underline">S</span> imple <span style="text-decoration: underline">O</span> bject <span style="text-decoration: underline">A</span> ccess <span style="text-decoration: underline">P</span> rotocol）。的确如它的名字一样，SOAP是很简单的。它是一个基于XML的协议，允许程序组件和应用程序彼此使用一种标准的Internet协议 --HTTP来通讯。SOAP是一种独立的平台，它不依赖程序语言，它是简单的，弹性的，很容易扩展的。目前，应用程序能够彼此使用一种基于DCOM和 CORBA技术的远程过程调用（RPC）来进行相互通讯，但HTTP不被设计为这个目的。RPC在Internet上应用是非常困难的，它们会出现许多兼容性和安全性的问题，因为<a href="http://zz.21tx.com/safe/firewall/" target="_blank"><span style="color: rgb(51,102,204)">防火墙</span> </a>和代理<a href="http://www.21tx.com/server/" target="_blank"><span style="color: rgb(51,102,204)">服务器</span> </a>通常都会阻断（block）这些类型的流量。应用程序之间最好的通讯方式是通过HTTP协议，因为HTTP是支持所有Internet浏览器和服务器的。基于这个目的，SOAP协议被创建出来。</span> </p>
<p><span style="font-size: medium">那么，它们是如何运作的呢？比如，一个应用程序（A）需要和另一个应用程序（B）在SOAP的帮助下进行彼此通讯。它们将使用下面的框架图来完成这个过程：</span> </p>
<p>&nbsp;</p>
<p><span style="font-size: medium"><img border="0" alt="" align="baseline" src="http://image.21tx.com/image/20040117/10157.gif" /> </span></p>
<p><span style="font-size: medium">这个SOAP信封（SOAP envelope）是一个包含以下内容的XML文档：</span> </p>
<p>&nbsp;</p>
<p><span style="font-size: medium"><img border="0" alt="" align="baseline" src="http://image.21tx.com/image/20040117/10165.gif" /> </span></p>
<p><span style="font-size: medium">正如你看到的，它是非常简单的。它看起来确实就象一个普通的信封或者你的 email。你想看看它们是如何动作的吗？下面跟我们一起来吧。其实我们有很多方法是不用SOAP来在创建和运行我们自己的&#8220;Hello World&#8221;应用程序的，但是因为我们要保持它的简单性，我会给你一个它运作方式的框架图（scheme）。</span> </p>
<p><span style="font-size: medium">我们的&#8220;Hello World&#8221;范例会包含一个SOAP Service。我们的SOAP Client将发送它们的名字到该SOAP Service，并试图得到一些答复或响应。这个SOAP Service需要部署到一个SOAP Admin的工具，以至重定位所有请求的SOAP（Proxy） RPC Router能够知道它们应该使用哪种服务来运作。总而言之，这个是以下面的方式来运作的：</span> </p>
<p>&nbsp;</p>
<p><span style="color: rgb(255,0,0); font-size: medium"><strong><img border="0" alt="" align="baseline" src="http://image.21tx.com/image/20040117/10168.gif" /> </strong></span></p>
<p><span style="font-size: medium">现在，我们来一步步的看看到底发生了什么。在Step 1里，HelloWorldClient将连接一个SOAP RPC Router，请求我们的SOAP Service并将包含我们名字的一个字符串传递给它。该SOAP RPC Router会检查是否它已经部署了这个SOAP Service。如果它被发现是被部署的，那么它将传递数据到这个SOAP Service并调用特定的方法，这个是Step 2。然后SOAP Service方法会被执行，将返回某个字符串值（该值就是SOAP Client的答复或者响应）（Step 3）。在Step4中，SOAP RPC Router将仅仅只是重定向这个数据到SOAP Client。所有在Step1和Step4里传输的数据是通过SOAP Envelope来完成的。正如你所看到的，算法是相当简单的，因此我们只准备关心实际的代码。</span> </p>
<p><span style="font-size: medium">首先，我们要创建一个SOAP Service。下面是它的代码，请不要忘记将它放入HelloWorld/ 目录中（必须被包含在你的CLASSPATH中）：</span> </p><pre><span style="font-size: medium">1: // SOAPService.java
2: package HelloWorld;
3: public class SOAPService {
4:   public String sayHi(String x) {
5:     return("Hello my friend, " + x + "! Glad to see you!");
6:   }
7: }
</span>
</pre>
<p><span style="font-size: medium">添加任何注释也是很容易的。要编译它，只需要用下列命令：</span> </p><pre><span style="font-size: medium">javac SOAPService.java</span>
</pre>
<p><span style="font-size: medium">第二步，一旦我们准备好了SOAP Service，我们需要用SOAP Service Manager来部署它。这个可以通过很多方式来实现，但是为了能让初学SOAP的读者更容易理解SOAP，我提供了一个最容易的方式。我们假设你的<a href="http://dev.21tx.com/web/" target="_blank"><span style="color: rgb(51,102,204)">Web</span> </a>Server（Tomcat或其他）已经正常运行，并且你已经正确安装了SOAP。那么当浏览器访问</span> <a href="http://localhost:8080/soap/"><span style="color: rgb(51,102,204); font-size: medium">http://localhost:8080/soap/</span> </a><span style="font-size: medium">，你会看见Apache SOAP的欢迎页面。点击<em><span style="text-decoration: underline">Run the admin client</span> </em>，然后 <em><span style="text-decoration: underline">Deploy</span> </em>。你会得到一个屏幕显示，在那里你需要填入ID，Scope，Method，Provider Type和JAVA Provider的信息到表单域中。你能忽略其他所有的表单域，除非你真的需要它们的信息。我们的&#8220;HelloWorld&#8221;例子不需要它们，所以，我们填的下面的值：</span> </p>
<p>&nbsp;</p>
<table border="0">
<tbody>
<tr>
<td><span style="font-size: medium"><em>ID:</em> </span></td>
<td><span style="font-size: medium">urn:HelloWorld_SOAPService</span> </td></tr>
<tr>
<td><span style="font-size: medium"><em>Scope:</em> </span></td>
<td><span style="font-size: medium">Application</span> </td></tr>
<tr>
<td><span style="font-size: medium"><em>Methods:</em> </span></td>
<td><span style="font-size: medium">sayHi</span> </td></tr>
<tr>
<td><span style="font-size: medium"><em>Provider Type:</em> </span></td>
<td><span style="font-size: medium">java</span> </td></tr>
<tr>
<td><span style="font-size: medium"><em>Java Provider - Provider Class:</em> </span></td>
<td><span style="font-size: medium">HelloWorld.SOAPService</span> </td></tr>
<tr>
<td><em><span style="font-size: medium">Java Provider - Static?</span> </em></td>
<td><span style="font-size: medium">No</span> </td></tr></tbody></table>
<p><span style="font-size: medium">一些注释：ID是我们要从SOAP Client标识我们的SOAP Service的唯一名字。Method包含SOAP Service提供的一系列方法。JAVA Provider-Provider Class是SOAP Service Java类的名字。</span> </p>
<p><span style="font-size: medium">现在，点击<em><span style="text-decoration: underline">Deploy</span> </em>按钮，那么你的服务会被部署。再次强调，请注意正确设置CLASSPATH环境变量。然后，你的HelloWorld.SOAPService类能够被找到，并且所有必需的jar包也能被找到。这是个几乎每个人都会犯的普通错误。现在，你能够点击 <em><span style="text-decoration: underline">List</span> </em>，将会看见你的服务已经被部署进来。恭喜！</span> </p>
<p><span style="font-size: medium">最后，让我们来创建一个SOAP Client。代码看起来有点复杂，但是在现实中不会只有这么点长。</span> </p><pre><span style="font-size: medium"> 1: // HelloWorldClient.java
2: import java.io.*;
3: import java<a href="http://dev.21tx.com/dotnet/" target="_blank">.net
</a>
.*;
4: import java.util.*;
5: import org.apache.soap.*;
6: import org.apache.soap.rpc.*;
7: public class HelloWorldClient {
8:   public static void main(String[] arg) throws Exception {
9:     Call c = null;
10:     URL url = null;
11:     Vector params = null;
12:     Response rep = null;
13:     String ourName = "Superman";
14:     String ourUrn = "urn:HelloWorld_SOAPService";
15:     String ourMethod = "sayHi";
16:     url = new URL("http://localhost:8080/soap/<a href="http://dev.21tx.com/java/jsp/" target="_blank">Servlet
</a>
/
rpcrouter");
17:     System.out.println("Passing to our deployed "+ourUrn+"
our name ("+ourName+"): ");
18:     c = new Call();
19:     c.setTargetObjectURI(ourUrn);
20:     c.setMethodName(ourMethod);
21:     c.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
22:     params = new Vector();
23:     params.addElement(new Parameter("ourName", String.class,
ourName, null));
24:     c.setParams(params);
25:     System.out.print("and its answer is: ");
26:     rep = c.invoke(url, "");
27:     if (rep.generatedFault()) {
28:       Fault fault = rep.getFault();
29:       System.out.println("\nCall failed!");
30:       System.out.println("Code = " + fault.getFaultCode());
31:       System.out.println("String = " + fault.getFaultString());
32:     } else {
33:       Parameter result = rep.getReturnValue();
34:       System.out.print(result.getValue());
35:       System.out.println();
36:     }
37:   }
38:}
</span>
</pre>
<p><span style="font-size: medium">下面我要做一些解释。在第13行，我们设置了我们的名字，这个名字将会传递给 SOAP Service。在第14行，我们设置了我们将要调用的服务的ID（service ID），和第15行里设置的服务方法（service method）。有了这个ID，服务能够被部署到SOAP服务管理器（SOAP Service Manager）中。我们没有设置任何其他值，仅仅只用刚才那些基础值就可以正常运作了。你能从SOAP的官方文档上得到相关信息，该文档来自SOAP包中，它们的解释超出了本文的范围。</span> </p>
<p><span style="font-size: medium">用以下方式编译这个SOAP Client：</span> </p><pre><span style="font-size: medium">javac HelloWorldClient.java</span>
</pre>
<p><span style="font-size: medium">为了圆满完成它，让我们检查一下针对我们的测试，是否所有事情都准备就绪。Tomcat正在运行，所有的环境变量都正确，SOAP Service被编译和部署，SOAP Client被成功编译。OK，让我们运行它，你将看到这个屏幕：</span> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-size: medium"><img border="0" alt="" align="baseline" src="http://image.21tx.com/image/20040117/10154.gif" /> </span></p>
<p><span style="font-size: medium">正如你所看到的，我们的SOAP Client使用SOAP协议成功发送它的名字和接收了一个答复。正如前面所说的，SOAP Service发送和接收的是SOAP envelope。这个是SOAP envelope的源代码。</span> </p>
<p><em><span style="font-size: medium">被<strong>发送</strong> 到SOAP Service的SOAP Envelope</span> </em></p><pre><span style="font-size: medium">&lt;?<a href="http://dev.21tx.com/web/xml/" target="_blank">XML
</a>
version='1.0' encoding='UTF-8'?&gt;
&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/
soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;SOAP-ENV:Body&gt;
&lt;ns1:sayHi xmlns:ns1="urn:HelloWorld_SOAPService"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/
soap/encoding/"&gt;
&lt;ourName xsi:type="xsd:string"&gt;Superman&lt;/ourName&gt;
&lt;/ns1:sayHi&gt;
&lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;:
</span>
</pre>
<p><em><span style="font-size: medium">从SOAP Service<strong>接收</strong> 的SOAP Envelope</span> </em></p><pre><span style="font-size: medium">&lt;?xml version='1.0' encoding='UTF-8'?&gt;
&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/
soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;SOAP-ENV:Body&gt;
&lt;ns1:sayHiResponse xmlns:ns1="urn:HelloWorld_SOAPService"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.
org/soap/encoding/"&gt;
&lt;return xsi:type="xsd:string"&gt;Hello my friend, Superman!
Glad to see you!&lt;/return&gt;
&lt;/ns1:sayHiResponse&gt;
&lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;
</span>
</pre>
<p><span style="font-size: medium">要理解SOAP Envelope中的所有标签的含义，我建议你花一点时间阅读 </span><a href="http://www.w3.org/2001/06/soap-envelope" target="new"><span style="text-decoration: underline"><span style="color: rgb(0,0,255); font-size: medium">http://www.w3.org/2001/06/soap-envelope</span> </span></a><span style="font-size: medium">命名空间规范。</span> </p>
<p><span style="font-size: medium">我希望本文能够在你理解SOAP技术上有一定帮助。这个技术是简单的，有趣的，强大的，弹性的。它被用在许多Web应用中，这些应用的数量也在不断增加。学习SOAP是值得的，至少你要知道它是什么和它是怎么运作的</span></p><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/389671.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-10-16 16:41 <a href="http://www.blogjava.net/baizhihui19870626/articles/389671.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Ibatis insert后返回值为null的解决办法（转） </title><link>http://www.blogjava.net/baizhihui19870626/articles/389469.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Fri, 12 Oct 2012 07:57:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/389469.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/389469.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/389469.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/389469.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/389469.html</trackback:ping><description><![CDATA[关于com.ibatis.sqlmap.client.SqlMapExecutor下的insert (java.lang.String id, java.lang.Object parameterObject) 方法，ibatis的api文档是这样写的解释的： <br /><br />Java代码 <br />Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional. <br /><br />The parameter object is generally used to supply the input data for the INSERT values. <br /><br />Parameters: <br />id - The name of the statement to execute. <br />parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.). <br />Returns: <br />The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source. <br />Throws: <br />java.sql.SQLException - If an error occurs. <br /><br />Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional. <br /><br />The parameter object is generally used to supply the input data for the INSERT values. <br /><br />Parameters: <br />id - The name of the statement to execute. <br />parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.). <br />Returns: <br />The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source. <br />Throws: <br />java.sql.SQLException - If an error occurs. <br /><br /><br />它的意思是说返回值是新插入记录的主键，类型为Object主要是因为主键类型可以是int也可以是String类型。 <br /><br />然而，如果我们使用下列的配置文件进行插入的话，返回的值为null <br /><br />Xml代码 <br />&lt;insert id="insertPrdcategory" parameterClass="Prdcategory"&gt; <br />insert into Prdcategory ( name,pid,deep ) values ( #name#, <br />#pid#, #deep# ) <br />&lt;/insert&gt; <br /><br />&lt;insert id="insertPrdcategory" parameterClass="Prdcategory"&gt; <br />insert into Prdcategory ( name,pid,deep ) values ( #name#, <br />#pid#, #deep# ) <br />&lt;/insert&gt; <br /><br />那我们要怎样解决这个问题，让它返回插入行的主键呢，这时我们就是使用到&lt;selectKey&gt;,下面仅以MSSQL数据库为例，改写上述配置文件，具体如下： <br /><br /><br /><br />Xml代码 <br />&lt;insert id="insertPrdcategory" parameterClass="Prdcategory"&gt; <br />insert into Prdcategory ( name,pid,deep ) values ( #name#, <br />#pid#, #deep# ) <br />&lt;selectKey resultClass="int" keyProperty="id"&gt; <br />select max(id) from Prdcategory <br />&lt;/selectKey&gt; <br />&lt;/insert&gt; <br /><br />&lt;insert id="insertPrdcategory" parameterClass="Prdcategory"&gt; <br />insert into Prdcategory ( name,pid,deep ) values ( #name#, <br />#pid#, #deep# ) <br />&lt;selectKey resultClass="int" keyProperty="id"&gt; <br />select max(id) from Prdcategory <br />&lt;/selectKey&gt; <br />&lt;/insert&gt; <br /><br /><br />DAO的实现类方法里面就应该这样写了（注意整型转换用Integer类名） <br /><br />Java代码 <br />public int insertPrdcategory(Prdcategory product) throws Exception { <br />return (Integer)IbatisUtil.getSqlMapper().insert("insertPrdcategory", product); <br />} <br /><br />public int insertPrdcategory(Prdcategory product) throws Exception { <br />return (Integer)IbatisUtil.getSqlMapper().insert("insertPrdcategory", product); <br />} <br /><br /><br />这样就算是OK了。 <br /><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/389469.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-10-12 15:57 <a href="http://www.blogjava.net/baizhihui19870626/articles/389469.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>华为彩信模拟器的参数设置 </title><link>http://www.blogjava.net/baizhihui19870626/articles/388497.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Tue, 25 Sep 2012 04:49:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388497.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388497.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388497.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388497.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388497.html</trackback:ping><description><![CDATA[<div class="blog_title">
<h3><a href="http://peahen.iteye.com/blog/414312">华为彩信模拟器的参数设置</a> <em class="actions"></em></h3>
<div class="news_tag"><a href="http://www.iteye.com/blogs/tag/%E5%8D%8E%E4%B8%BA">华为</a><a href="http://www.iteye.com/blogs/tag/SOAP">SOAP</a><a href="http://www.iteye.com/blogs/tag/XML">XML</a><a href="http://www.iteye.com/blogs/tag/SUN">SUN</a><a href="http://www.iteye.com/blogs/tag/IDEA">IDEA</a> </div></div>
<div id="blog_content" class="blog_content">最近开发了一个SP的彩信接入系统，代码编写完成后，觉得有必要进行接发测试。从网上下载来华为彩信模拟器，测试过程中发现始终无法成功。不得已使用DJ Java Decompiler反汇编了一下代码，经过简单分析终于才了解到接发的URL地址和端口如何填写，真是不知道为什么华为不把文档写详细一点，搞得大家开发那么累。 <br />1、mm7Config.xml中的ListenIP、ListenPort分别是接收彩信时的监听地址和端口，这里我使用了127.0.0.1和9080，对应华为彩信模拟器的Send to应该填写http://127.0.0.1:9080/Receiver。 <br />2、mm7Config.xml中的mmscURL、mmscIP分别是彩信中心接收彩信时的URL和IP地址，这里我使用了/vas和127.0.0.1，对应华为彩信模拟器的Listener Port填写80即可。 <br />这样对mm7Config.xml和华为彩信模拟器进行了适当的修改，启动自己开发的彩信接入系统。点击&#8220;Send&#8221;按钮，命令窗口还是报错，具体如下： <br /><span style="color: blue">错误：&#8220;没有说明名称空间前缀&#8220;soap-env&#8221;。&#8221; <br />2009-6-24 17:20:05 com.sun.xml.internal.messaging.saaj.soap.MessageImpl writeTo <br />严重: SAAJ0540: Error during saving a multipart message</span> <br />这个问题稍微麻烦一点，需要在系统属性中设置javax.xml.soap.MessageFactory和javax.xml.soap.SOAPConnectionFactory。实际上华为的彩信模拟器MMSCSimulation.exe是一个可执行的jar包，用WinRar将该文件展开到你的工作目录下，然后执行java -Xmx1024m -Xms1024m -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.MessageFactoryImpl -Djavax.xml.soap.SOAPConnectionFactory=com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory com.huawei.mms.simulation.MM7Simulation启动模拟器，就可以进行测试啦。 <br /><img src="http://peahen.iteye.com/upload/attachment/118350/d4885527-e9b4-374f-b892-ea316f845ca5.jpg"  alt="" /> </div>
<div class="attachments">
<ul style="display: none"><li><a href="http://dl.iteye.com/upload/attachment/0011/8350/d4885527-e9b4-374f-b892-ea316f845ca5.jpg" target="_blank"><img class="magplus" title="点击查看原始大小图片" src="http://dl.iteye.com/upload/attachment/0011/8350/d4885527-e9b4-374f-b892-ea316f845ca5-thumb.jpg"  alt="" /></a></li><li>大小: 55.7 KB </li></ul></div><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-25 12:49 <a href="http://www.blogjava.net/baizhihui19870626/articles/388497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MM7 </title><link>http://www.blogjava.net/baizhihui19870626/articles/mm7.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Tue, 25 Sep 2012 03:40:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/mm7.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388491.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/mm7.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388491.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388491.html</trackback:ping><description><![CDATA[<div>中兴MM7接口开发</div>
<div>2010-03-11 14:44</div>
<div>1，发送彩信的时候一直报告说连接超时,返回好像是-104 ,检查了网络 ping IP telnet 端口似乎都好的,后来抓包才发现,发彩信的时候数据一直走80端口,不会走配置上的端口,后来才发现原来要改端口的话是要在这里&lt;mmscIP&gt;10.103.122.180:8080&lt;/mmscIP&gt;加上端口号才行的.</div>
<div>2，返回4007 等 一般都是参数加的有问题 比如号码+86,serviceCode VASPID sendAddress等</div>
<div>3，mm7api的文档里面对于smil彩信，就说了一个含smil的彩信，必须把content-type设置成multipart-related，如果按照文档里面的流程，即使你怎么组合，smil都不起作用的，即使你setPresentionContent(smil)了，照样不起作用。原因很简单，mixed方式发送彩信，只需要setContentID()就行，而related方式，必须把每一个subContent都setContentID()和setContentLocation()，这两项的内容最好相同，比如都为他们的文件名。</div>
<div>(如果不填这两个发下去的时候在诺基亚的手机里面就只能看到下发的所有文件列表,而且文件的名字和原来的不一样 ,比如原来为001.jpg 在手机里面就显示file001.jpg,设置了这两个参数之后一切正常);</div>
<div><br /></div>
<div>
<div>中兴MM7接口开发</div>
<div>2010-03-11 14:44</div>
<div>1，发送彩信的时候一直报告说连接超时,返回好像是-104 ,检查了网络 ping IP telnet 端口似乎都好的,后来抓包才发现,发彩信的时候数据一直走80端口,不会走配置上的端口,后来才发现原来要改端口的话是要在这里&lt;mmscIP&gt;10.103.122.180:8080&lt;/mmscIP&gt;加上端口号才行的.</div>
<div>2，返回4007 等 一般都是参数加的有问题 比如号码+86,serviceCode VASPID sendAddress等</div>
<div>3，mm7api的文档里面对于smil彩信，就说了一个含smil的彩信，必须把content-type设置成multipart-related，如果按照文档里面的流程，即使你怎么组合，smil都不起作用的，即使你setPresentionContent(smil)了，照样不起作用。原因很简单，mixed方式发送彩信，只需要setContentID()就行，而related方式，必须把每一个subContent都setContentID()和setContentLocation()，这两项的内容最好相同，比如都为他们的文件名。</div>
<div>(如果不填这两个发下去的时候在诺基亚的手机里面就只能看到下发的所有文件列表,而且文件的名字和原来的不一样 ,比如原来为001.jpg 在手机里面就显示file001.jpg,设置了这两个参数之后一切正常);</div></div>
<div><br /></div>
<div><br /></div>
<div>
<p style="text-align: left; padding-bottom: 0px; line-height: 25px; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px">今天终于发出了彩信了，移动的MM7文档写的太不全了，折腾了好几天，总算是发出去了。MM7ApiI文件如下</p>
<div style="text-align: left; padding-bottom: 1px; line-height: 25px; padding-left: 1px; width: 679px; padding-right: 1px; margin-left: 9px; padding-top: 1px" class="dp-highlighter">
<div class="bar">
<div style="padding-bottom: 3px; margin: 0px; padding-left: 3px; padding-right: 3px; font-weight: bold; padding-top: 3px" class="tools">Java代码 <a style="color: #108ac6" title="收藏这段代码" href="http://fxyc.iteye.com/blog/642098"><img class="star" alt="收藏代码" src="http://fxyc.iteye.com/images/icon_star.png" /></a> </div></div>
<ol style="border-bottom: #d1d7dc 1px solid; border-left: #d1d7dc 1px solid; padding-bottom: 2px; line-height: 1.4em; margin: 0px 0px 1px; padding-left: 0px; padding-right: 0px; color: #2b91af; font-size: 1em; border-top: #d1d7dc 1px solid; border-right: #d1d7dc 1px solid; padding-top: 2px" class="dp-j"><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> com.cmcc.mm7.vasp.message.*; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> com.cmcc.mm7.vasp.service.MM7Sender; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> com.cmcc.mm7.vasp.common.*; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> java.io.*; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> java.text.*; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">import</span> com.cmcc.mm7.vasp.conf.*; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">public</span> <span style="color: #7f0055; font-weight: bold" class="keyword">class</span> MM7Api </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">public</span> <span style="color: #7f0055; font-weight: bold" class="keyword">static</span> <span style="color: #7f0055; font-weight: bold" class="keyword">void</span> main(String[] args) </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">final</span> MM7Config mm7Config = <span style="color: #7f0055; font-weight: bold" class="keyword">new</span> MM7Config(<span style="color: blue" class="string">"./config/mm7Config.xml"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">mm7Config.setConnConfigName(<span style="color: blue" class="string">"./config/ConnConfig.xml"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">try</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">SimpleDateFormat sdf = <span style="color: #7f0055; font-weight: bold" class="keyword">new</span> SimpleDateFormat(<span style="color: blue" class="string">"yyyy-MM-dd'T'HH:mm:ss"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MM7SubmitReq submit = <span style="color: #7f0055; font-weight: bold" class="keyword">new</span> MM7SubmitReq(); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setTransactionID(<span style="color: blue" class="string">"13934557531"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.addTo(<span style="color: blue" class="string">""</span>); <span style="color: #008200" class="comment">//发送到的号码 </span></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setVASID(<span style="color: blue" class="string">""</span>);<span style="color: #008200" class="comment">//设置SP代码</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setVASPID(<span style="color: blue" class="string">""</span>); <span style="color: #008200" class="comment">//设置服务代码</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setServiceCode(<span style="color: blue" class="string">"0008"</span>);<span style="color: #008200" class="comment">//设置业务代码</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setSenderAddress(<span style="color: blue" class="string">"10086"</span>); <span style="color: #008200" class="comment">//设置MM始发方的地址</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setSubject(<span style="color: blue" class="string">"经营分析日报"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setChargedPartyID(<span style="color: blue" class="string">"13453417863"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setChargedParty((<span style="color: #7f0055; font-weight: bold" class="keyword">byte</span>)<span style="color: #c00000" class="number">4</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setDeliveryReport(<span style="color: #7f0055; font-weight: bold" class="keyword">true</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MMContent presentation = MMContent.createFromFile(<span style="color: blue" class="string">"./test.smil"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">presentation.setContentType( <span style="color: blue" class="string">"application/smil "</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">presentation.setContentID( <span style="color: blue" class="string">"test.smil "</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MMContent maincontent = <span style="color: #7f0055; font-weight: bold" class="keyword">new</span> MMContent(); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.setContentID( <span style="color: blue" class="string">"main "</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.setContentType(MMConstants.ContentType.MULTIPART_RELATED); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.addSubContent(presentation); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">/* MMContent content = new MMContent();</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">content.setContentType(MMConstants.ContentType.MULTIPART_RELATED);</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">content.setContentID("main");</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment"></span></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">MMContent sub1 = MMContent.createFromFile("./test.smil");</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">sub1.setContentID("test.smil");</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">sub1.setContentType(MMConstants.ContentType.SMIL);</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">sub1.setContentLocation("test.smil");</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">content.addSubContent(sub1);</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #008200" class="comment">*/</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MMContent sub2 = MMContent.createFromFile(<span style="color: blue" class="string">"./smil.txt"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub2.setContentID(<span style="color: blue" class="string">"smil.txt"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub2.setContentType(MMConstants.ContentType.TEXT); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.addSubContent(sub2); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MMContent sub3 = MMContent.createFromFile(<span style="color: blue" class="string">"./a.GIF"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub3.setContentID(<span style="color: blue" class="string">"a.GIF"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub3.setContentType(MMConstants.ContentType.GIF); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.addSubContent(sub3); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MMContent sub4 = MMContent.createFromFile(<span style="color: blue" class="string">"./2.txt"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub4.setContentID(<span style="color: blue" class="string">"2.txt"</span>); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">sub4.setContentType(MMConstants.ContentType.TEXT); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">maincontent.addSubContent(sub4); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">submit.setContent(maincontent); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MM7Sender mm7Sender = <span style="color: #7f0055; font-weight: bold" class="keyword">new</span> MM7Sender(mm7Config); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MM7RSRes rsRes; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">rsRes = (MM7RSRes)mm7Sender.send(submit); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">if</span>(rsRes <span style="color: #7f0055; font-weight: bold" class="keyword">instanceof</span> MM7SubmitRes) </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">MM7SubmitRes submitRes = (MM7SubmitRes)rsRes; </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">System.out.println(rsRes.getTransactionID()); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">System.out.println(<span style="color: blue" class="string">"after!!submitRes.statuscode="</span> + rsRes.getStatusCode() + <span style="color: blue" class="string">";submitRes.statusText="</span> + rsRes.getStatusText()); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">}<span style="color: #7f0055; font-weight: bold" class="keyword">else</span>{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">System.out.println(<span style="color: blue" class="string">"do！rsRes.statuscode="</span>+rsRes.getStatusCode() + <span style="color: blue" class="string">";rsRes.statusText="</span> + rsRes.getStatusText()); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">} </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">} </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #7f0055; font-weight: bold" class="keyword">catch</span> (Exception e) </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">{ </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">System.out.println(e); </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">} </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">} </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black">} </span></li></ol></div>
<p style="text-align: left; padding-bottom: 0px; line-height: 25px; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px">smil文件格式如下：</p>
<div style="text-align: left; padding-bottom: 1px; line-height: 25px; padding-left: 1px; width: 679px; padding-right: 1px; margin-left: 9px; padding-top: 1px" class="dp-highlighter">
<div class="bar">
<div style="padding-bottom: 3px; margin: 0px; padding-left: 3px; padding-right: 3px; font-weight: bold; padding-top: 3px" class="tools">Xml代码 <a style="color: #108ac6" title="收藏这段代码" href="http://fxyc.iteye.com/blog/642098"><img class="star" alt="收藏代码" src="http://fxyc.iteye.com/images/icon_star.png" /></a> </div></div>
<ol style="border-bottom: #d1d7dc 1px solid; border-left: #d1d7dc 1px solid; padding-bottom: 2px; line-height: 1.4em; margin: 0px 0px 1px; padding-left: 0px; padding-right: 0px; color: #2b91af; font-size: 1em; border-top: #d1d7dc 1px solid; border-right: #d1d7dc 1px solid; padding-top: 2px" class="dp-xml"><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">smil</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">head</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">layout</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">root-layout</span> <span style="color: red" class="attribute">width</span>=<span style="color: blue" class="attribute-value">"320"</span> <span style="color: red" class="attribute">height</span>=<span style="color: blue" class="attribute-value">"240"</span><span style="color: #006699; font-weight: bold" class="tag">/&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">region</span> <span style="color: red" class="attribute">id</span>=<span style="color: blue" class="attribute-value">"Image"</span> <span style="color: red" class="attribute">width</span>=<span style="color: blue" class="attribute-value">"220"</span> <span style="color: red" class="attribute">height</span>=<span style="color: blue" class="attribute-value">"260"</span> <span style="color: red" class="attribute">left</span>=<span style="color: blue" class="attribute-value">"76"</span> <span style="color: red" class="attribute">top</span>=<span style="color: blue" class="attribute-value">"34"</span><span style="color: #006699; font-weight: bold" class="tag">/&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">region</span> <span style="color: red" class="attribute">id</span>=<span style="color: blue" class="attribute-value">"Text"</span> <span style="color: red" class="attribute">width</span>=<span style="color: blue" class="attribute-value">"168"</span> <span style="color: red" class="attribute">height</span>=<span style="color: blue" class="attribute-value">"20"</span> <span style="color: red" class="attribute">left</span>=<span style="color: blue" class="attribute-value">"76"</span> <span style="color: red" class="attribute">top</span>=<span style="color: blue" class="attribute-value">"220"</span><span style="color: #006699; font-weight: bold" class="tag">/&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">layout</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">head</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">body</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">par</span> <span style="color: red" class="attribute">dur</span>=<span style="color: blue" class="attribute-value">"20s"</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">img</span> <span style="color: red" class="attribute">src</span>=<span style="color: blue" class="attribute-value">"23.jpeg"</span> <span style="color: red" class="attribute">region</span>=<span style="color: blue" class="attribute-value">"Image"</span> <span style="color: #006699; font-weight: bold" class="tag">/&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">text</span> <span style="color: red" class="attribute">src</span>=<span style="color: blue" class="attribute-value">"smil.txt"</span> <span style="color: red" class="attribute">region</span>=<span style="color: blue" class="attribute-value">"Text"</span> <span style="color: #006699; font-weight: bold" class="tag">/&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">par</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">par</span> <span style="color: red" class="attribute">dur</span>=<span style="color: blue" class="attribute-value">"20s"</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">img</span> <span style="color: red" class="attribute">src</span>=<span style="color: blue" class="attribute-value">"23.jpg"</span> <span style="color: red" class="attribute">region</span>=<span style="color: blue" class="attribute-value">"Image"</span> <span style="color: red" class="attribute">begin</span>=<span style="color: blue" class="attribute-value">"0s"</span> <span style="color: red" class="attribute">end</span>=<span style="color: blue" class="attribute-value">"20s"</span> <span style="color: #006699; font-weight: bold" class="tag">&gt;</span><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">img</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;</span><span style="color: #006699; font-weight: bold" class="tag-name">text</span> <span style="color: red" class="attribute">src</span>=<span style="color: blue" class="attribute-value">"2.txt"</span> <span style="color: red" class="attribute">region</span>=<span style="color: blue" class="attribute-value">"Text"</span> <span style="color: red" class="attribute">begin</span>=<span style="color: blue" class="attribute-value">"0s"</span> <span style="color: red" class="attribute">end</span>=<span style="color: blue" class="attribute-value">"20s"</span> <span style="color: #006699; font-weight: bold" class="tag">&gt;</span><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">text</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">par</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"></span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">body</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li><li style="border-left: #d1d7dc 1px solid; padding-bottom: 0px; line-height: 18px; background-color: #fafafa; margin: 0px 0px 0px 38px; padding-left: 10px; padding-right: 0px; font-size: 1em; padding-top: 0px"><span style="color: black"><span style="color: #006699; font-weight: bold" class="tag">&lt;/</span><span style="color: #006699; font-weight: bold" class="tag-name">smil</span><span style="color: #006699; font-weight: bold" class="tag">&gt;</span> </span></li></ol></div>
<p style="text-align: left; padding-bottom: 0px; line-height: 25px; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px"><span style="font-size: small"><font size="2">需要特别主要的是</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 25px; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px"><span style="font-size: small"><font size="2">1.</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 21px; margin: 0cm 0cm 0pt; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px" class="MsoNormal"><span style="font-size: small"><font size="2">submitReq.setVASPID("SP代码") ; //设置SP代码</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 21px; margin: 0cm 0cm 0pt; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px" class="MsoNormal"><span style="font-size: small"><font size="2">submitReq.setVASID("服务代码") ; //设置服务代码</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 21px; margin: 0cm 0cm 0pt; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px" class="MsoNormal"><span style="font-size: small"><font size="2">submitReq.setServiceCode("业务代码"); //设置业务代码</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 21px; margin: 0cm 0cm 0pt; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px" class="MsoNormal"><span style="font-size: small"><font size="2">如果出现rsRes.statuscode=4007;rsRes.statusText=Authority failed为鉴权失败，一般为上述设置不对。</font></span></p>
<p style="text-align: left; padding-bottom: 0px; line-height: 21px; margin: 0cm 0cm 0pt; padding-left: 0px; padding-right: 0px; font-size: 14px; padding-top: 0px" class="MsoNormal"><span style="font-size: small"><font size="3"><span style="font-size: medium"><strong style="font-weight: bold">2</strong></span></font><font size="2">.当时我是只把smil文件传上去，以为有了这个文件系统会根据路径来读取所有的文件，其实不然，smil中出现的文件都得自己加到MMContent中上传到服务器。</font></span></p></div><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-25 11:40 <a href="http://www.blogjava.net/baizhihui19870626/articles/mm7.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CMPP和SMPP协议比较</title><link>http://www.blogjava.net/baizhihui19870626/articles/388433.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Mon, 24 Sep 2012 06:28:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388433.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388433.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388433.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388433.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388433.html</trackback:ping><description><![CDATA[<h1><span lang="EN-US">CMPP</span><span style="font-family: 宋体">和</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">协议比较</span></h1>
<p class="MsoNormal"><span lang="EN-US"><O:P></O:P></span></p>
<h2><span style="font-family: 黑体">并非同类型协议</span><span style="line-height: 173%; font-size: 22pt" lang="EN-US"><O:P></O:P></span></h2>
<p class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">和</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">都是短信协议中的一种，但它们不是同一类型的协议。</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">和</span><span lang="EN-US">ESME</span><span style="font-family: 宋体">和</span><span lang="EN-US">SMC</span><span style="font-family: 宋体">（短信中心）之间的协议，而</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">是</span><span lang="EN-US">SP</span><span style="font-family: 宋体">和中国移动</span><span lang="EN-US">ISMG</span><span style="font-family: 宋体">之间的通讯协议。</span></p>
<p class="MsoNormal"><span style="font-family: 宋体">以下是</span><span lang="EN-US">CMPP 3.0</span><span style="font-family: 宋体">文档中的图示。</span></p>
<p class="MsoNormal"><span lang="EN-US"><V:SHAPETYPE id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><V:STROKE joinstyle="miter"></V:STROKE><V:FORMULAS><V:F eqn="if lineDrawn pixelLineWidth 0"></V:F><V:F eqn="sum @0 1 0"></V:F><V:F eqn="sum 0 0 @1"></V:F><V:F eqn="prod @2 1 2"></V:F><V:F eqn="prod @3 21600 pixelWidth"></V:F><V:F eqn="prod @3 21600 pixelHeight"></V:F><V:F eqn="sum @0 0 1"></V:F><V:F eqn="prod @6 1 2"></V:F><V:F eqn="prod @7 21600 pixelWidth"></V:F><V:F eqn="sum @8 21600 0"></V:F><V:F eqn="prod @7 21600 pixelHeight"></V:F><V:F eqn="sum @10 21600 0"></V:F></V:FORMULAS><V:PATH o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></V:PATH><O:LOCK v:ext="edit" aspectratio="t"></O:LOCK></V:SHAPETYPE><V:SHAPE style="width: 358.5pt; height: 256.5pt" id="_x0000_i1026" type="#_x0000_t75"><V:IMAGEDATA src="file:///C:\DOCUME~1\温少\LOCALS~1\Temp\msohtml1\01\clip_image001.png" o:title=""></V:IMAGEDATA></V:SHAPE>&lt;!--[if !vml]--&gt;<img border="0" alt="cmpp_001.JPG" src="http://images.cnblogs.com/cnblogs_com/jobs/cmpp_001.JPG" width="478" height="342" /><br />&lt;!--[endif]--&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 宋体">与</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">对应的协议有，联通的</span><span lang="EN-US">SGIP</span><span style="font-family: 宋体">协议，中国电信的</span><span lang="EN-US">SMGP</span><span style="font-family: 宋体">协议，网通的</span><span lang="EN-US">CNGP</span><span style="font-family: 宋体">协议。</span></p>
<p class="MsoNormal"><span style="font-family: 宋体">作为</span><span lang="EN-US">SP</span><span style="font-family: 宋体">，只需要了解</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">，不需要了解</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">。</span></p>
<h2><span style="font-family: 黑体">最新版本和兼容</span></h2>
<p class="MsoNormal"><span lang="EN-US">SMPP</span><span style="font-family: 宋体">协议是一个国际标准，有</span><span lang="EN-US">SMS</span><span style="font-family: 宋体">论坛制定，官方网址为</span><span lang="EN-US">smsforum.net</span><span style="font-family: 宋体">，截至</span><ST1:CHSDATE isrocdate="False" islunardate="False" day="2" month="7" year="2006" w:st="on"><span lang="EN-US">2006</span><span style="font-family: 宋体">年</span><span lang="EN-US">7</span><span style="font-family: 宋体">月</span><span lang="EN-US">2</span><span style="font-family: 宋体">日</span></ST1:CHSDATE><span style="font-family: 宋体">，最新版本是</span><span lang="EN-US">5.0</span><span style="font-family: 宋体">。曾经流行的版本是</span><span lang="EN-US">3.3</span><span style="font-family: 宋体">、</span><span lang="EN-US">3.4</span><span style="font-family: 宋体">。</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">协议向后兼容的。</span></p>
<p class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">最新版本似乎是</span><span lang="EN-US">3.0</span><span style="font-family: 宋体">。现在（</span><span lang="EN-US">2006</span><span style="font-family: 宋体">年</span><span lang="EN-US">7</span><span style="font-family: 宋体">月），大多数还是使用</span><span lang="EN-US">CMPP 2.0</span><span style="font-family: 宋体">。</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">协议没有做到向后兼容，</span><span lang="EN-US">3.0</span><span style="font-family: 宋体">的文档本身也没有讲到兼容的问题，甚至认为，协议制定者压根没想过要兼容。</span><span lang="EN-US">CMPP 3.0</span><span style="font-family: 宋体">没做到向后兼容导致了一个问题，就是</span><span lang="EN-US">SP</span><span style="font-family: 宋体">无法平滑升级。</span></p>
<h2><span lang="EN-US">PDU</span><span style="font-family: 黑体">格式</span></h2>
<p class="MsoNormal"><span lang="EN-US">PDU</span><span style="font-family: 宋体">是协议数据单元的缩写，</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">和</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">都使用最先一个</span><span lang="EN-US">4</span><span style="font-family: 宋体">位的长度标志整个</span><span lang="EN-US">PDU</span><span style="font-family: 宋体">的长度。</span></p>
<p class="MsoNormal"><span lang="EN-US"><V:GROUP style="width: 315.8pt; height: 195.8pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" id="_x0000_s1026" coordsize="6316,3916" editas="canvas" coordorigin="3232,4214"><O:LOCK v:ext="edit" aspectratio="t"></O:LOCK><V:SHAPE style="position: absolute" id="_x0000_s1027" o:preferrelative="f" type="#_x0000_t75"><V:FILL o:detectmouseclick="t"></V:FILL><V:PATH o:extrusionok="t" o:connecttype="none"></V:PATH><O:LOCK v:ext="edit" text="t"></O:LOCK></V:SHAPE><V:GROUP style="position: absolute" id="_x0000_s1028" coordsize="2340,3900" coordorigin="4500,4066"><V:RECT style="position: absolute" id="_x0000_s1029"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span lang="EN-US">SMPP Packet</span></p>
<p class="MsoNormal"><span lang="EN-US"><O:P></O:P></span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT><V:GROUP style="position: absolute" id="_x0000_s1030" coordsize="1980,3276" coordorigin="2700,4534"><V:RECT style="position: absolute" id="_x0000_s1031"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">消息头</span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT><V:RECT style="position: absolute" id="_x0000_s1032"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">必填参数</span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT><V:RECT style="position: absolute" id="_x0000_s1033"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可选参数</span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT></V:GROUP></V:GROUP><V:GROUP style="position: absolute" id="_x0000_s1034" coordsize="2340,3900" coordorigin="7200,4066"><V:RECT style="position: absolute" id="_x0000_s1035"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span lang="EN-US">CMPP Packet</span></p>
<p class="MsoNormal"><span lang="EN-US"><O:P></O:P></span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT><V:RECT style="position: absolute" id="_x0000_s1036"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">消息头</span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT><V:RECT style="position: absolute" id="_x0000_s1037"><V:TEXTBOX>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">消息体</span></p></div></td></tr></tbody></table></V:TEXTBOX></V:RECT></V:GROUP><W:WRAP type="none"></W:WRAP><W:ANCHORLOCK></W:ANCHORLOCK></V:GROUP>&lt;!--[if !vml]--&gt;<img border="0" alt="cmpp_002.JPG" src="http://images.cnblogs.com/cnblogs_com/jobs/cmpp_002.JPG" width="386" height="244" /><br />&lt;!--[endif]--&gt;</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">SMPP</span><span style="font-family: 宋体">是一个国际标准，不同的</span><span lang="EN-US">SMC</span><span style="font-family: 宋体">的是实现可能要增加特定参数，为了具备更好的扩展性，</span><span lang="EN-US">SMPP 3.4</span><span style="font-family: 宋体">以上版本，增加了可选参数，在</span><span lang="EN-US">5.0</span><span style="font-family: 宋体">中，可选参数叫做</span><span lang="EN-US">TLVTable</span><span style="font-family: 宋体">。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">是中国移动定义的其内部</span><span lang="EN-US">ISMG</span><span style="font-family: 宋体">之间、</span><span lang="EN-US">ISMG</span><span style="font-family: 宋体">与</span><span lang="EN-US">SP</span><span style="font-family: 宋体">之间的通讯标准，涉及一些具体的计费信息，但没有可选参数。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span style="font-family: 宋体">在</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">中，消息头包括</span><span lang="EN-US">4</span><span style="font-family: 宋体">部分：</span><span lang="EN-US">PDU</span><span style="font-family: 宋体">长度、</span><span lang="EN-US">Command_Id</span><span style="font-family: 宋体">、</span><span lang="EN-US">Command_Status</span><span style="font-family: 宋体">、</span><span lang="EN-US">Sequence_Id</span><span style="font-family: 宋体">。其中</span><span lang="EN-US">Command_Status</span><span style="font-family: 宋体">字段，只在回应消息中使用，存在冗余。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">中，消息头部包括</span><span lang="EN-US">3</span><span style="font-family: 宋体">部分：</span><span lang="EN-US">PDU</span><span style="font-family: 宋体">长度、</span><span lang="EN-US">Command_Id</span><span style="font-family: 宋体">、</span><span lang="EN-US">Sequence_Id</span><span style="font-family: 宋体">。个人认为，</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">中的消息头，不包括</span><span lang="EN-US">Command_Status</span><span style="font-family: 宋体">，似乎更好一些。</span></p>
<h2><span style="font-family: 黑体">消息传输模式</span></h2>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">SMPP</span><span style="font-family: 宋体">和</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">都支持异步传输，</span><span lang="EN-US">CMPP</span><span style="font-family: 宋体">中，建议异步传输的窗口大小为</span><span lang="EN-US">16</span><span style="font-family: 宋体">。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">使用一个连接发送短信息和接收短信息。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">SMPP</span><span style="font-family: 宋体">支持多种的连接，其中</span><span lang="EN-US">TX</span><span style="font-family: 宋体">类型的连接，只能发送短信息，</span><span lang="EN-US">RX</span><span style="font-family: 宋体">类型的连接只能接收短信息，</span><span lang="EN-US">TRX</span><span style="font-family: 宋体">类型的连接支持接收和发送短信息。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">SMPP 3.4</span><span style="font-family: 宋体">中，消息传输模式分三中：</span><span lang="EN-US">Store And Forward</span><span style="font-family: 宋体">、</span><span lang="EN-US">Datagram</span><span style="font-family: 宋体">、</span><span lang="EN-US">Forward</span><span style="font-family: 宋体">。分别用在大吞吐量、可靠性保证等不同的应用场合。</span></p>
<p style="text-indent: 21pt" class="MsoNormal"><span lang="EN-US">CMPP</span><span style="font-family: 宋体">没有规定其消息传输的模式，根据实际使用的情况看来，华为的网关的消息传输模式类似</span><span lang="EN-US">SMPP</span><span style="font-family: 宋体">协议中规定的</span><span lang="EN-US">Datagram</span><span style="font-family: 宋体">模式。</span></p><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388433.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-24 14:28 <a href="http://www.blogjava.net/baizhihui19870626/articles/388433.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>web.xml作用 </title><link>http://www.blogjava.net/baizhihui19870626/articles/388072.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Wed, 19 Sep 2012 07:15:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388072.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388072.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388072.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388072.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388072.html</trackback:ping><description><![CDATA[<p>web工程中的web.xml文件有什么作用呢？它是每个web.xml工程都必须的吗？</p>
<p>一个web中完全可以没有web.xml文件，也就是说，web.xml文件并不是web工程必须的。</p>
<p><br />那什么时候需要，什么时候可以不需要呢？</p>
<p>要想回答上面的问题，得先了解web.xml文件使用来干什么的。web.xml文件是用来配置：欢迎页、servlet、filter等的。当你的web工程没用到这些时，你可以不用web.xml文件来配置你的web工程。</p>
<p>那么web.xml能做的所有事情都有那些？</p>
<p>其实，web.xml的模式(Schema)文件中定义了多少种标签元素，web.xml中就可以出现它的模式文件所定义的标签元素，它就能拥有定义出来的那些功能。web.xml的模式文件是由Sun公司定义的，每个web.xml文件的根元素&lt;web-app&gt;中，都必须标明这个web.xml使用的是哪个模式文件。如：<br />&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />&lt;web-app version="2.5" <br />xmlns="<a href="http://java.sun.com/xml/ns/javaee" rel="nofollow">http://java.sun.com/xml/ns/javaee</a>" <br />xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance</a>" <br />xsi:schemaLocation="<a href="http://java.sun.com/xml/ns/javaee" rel="nofollow">http://java.sun.com/xml/ns/javaee</a> <br /><a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" rel="nofollow">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>"&gt;<br />&lt;/web-app&gt;</p>
<p>而且web.xml的模式文件中定义的标签并不是定死的，模式文件也是可以改变的，一般来说，随着web.mxl模式文件的版本升级，里面定义的功能会越来越复杂，也即标签元素的种类会越来越多，但有些是不常用的，我们只需记住一些常用的就可以了。</p>
<p><br />下面列出web.xml常用的标签元素及这些标签元素的功能：</p>
<p>1、指定欢迎页面，例如：<br />&lt;welcome-file-list&gt;<br />&lt;welcome-file-list&gt;<br />&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;<br />&lt;welcome-file&gt;index1.jsp&lt;/welcome-file&gt;<br />&lt;/welcome-file-list&gt;<br />上面的例子指定了2个欢迎页面，显示时按顺序从第一个找起，如果第一个存在，就显示第一个，后面的不起作用。如果第一个不存在，就找第二个，以此类推。</p>
<p>关于欢迎页面：</p>
<p>访问一个网站时，默认看到的第一个页面就叫欢迎页，一般情况下是由首页来充当欢迎页的。一般情况下，我们会在web.xml中指定欢迎页。但web.xml并不是一个Web的必要文件，没有web.xml，网站仍然是可以正常工作的。只不过网站的功能复杂起来后，web.xml的确有非常大用处，所以，默认创建的动态web工程在WEB-INF文件夹下面都有一个web.xml文件。<br />对于tomcat来说，当你只指定一个web的根名，没有指定具体页面，去访问时一个web时， 如果web.xml文件中配置了欢迎页，那么就返回指定的那个页面作为欢迎页，而在文中没有web.xml文件，或虽然有web.xml，但web.xml也没指定欢迎页的情况下，它默认先查找index.html文件，如果找到了，就把index.html作为欢迎页还回给浏览器。如果没找到index.html，tomcat就去找index.jsp。找到index.jsp就把它作为欢迎页面返回。而如果index.html和index.jsp都没找到，又没有用web.xml文件指定欢迎页面，那此时tomcat就不知道该返回哪个文件了，它就显示The requested resource (/XXX) is not available的页面。其中XXX表示web的根名。但如果你指定了具体页面，是可以正常访问的。</p>
<p>2、命名与定制URL。我们可以为Servlet和JSP文件命名并定制URL,其中定制URL是依赖一命名的，命名必须在定制URL前。下面拿serlet来举例：<br />(1)、为Servlet命名：<br />&lt;servlet&gt;<br />&lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;<br />&lt;servlet-class&gt;net.test.TestServlet&lt;/servlet-class&gt;<br />&lt;/servlet&gt;</p>
<p>(2)、为Servlet定制URL、<br />&lt;servlet-mapping&gt;<br />&lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;<br />&lt;url-pattern&gt;*.do&lt;/url-pattern&gt;<br />&lt;/servlet-mapping&gt;</p>
<p><br />3、定制初始化参数：可以定制servlet、JSP、Context的初始化参数，然后可以再servlet、JSP、Context中获取这些参数值。下面哪servlet来举例：<br />&lt;servlet&gt;<br />&lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;<br />&lt;servlet-class&gt;net.test.TestServlet&lt;/servlet-class&gt;<br />&lt;init-param&gt;<br />&lt;param-name&gt;userName&lt;/param-name&gt;<br />&lt;param-value&gt;Tommy&lt;/param-value&gt;<br />&lt;/init-param&gt;<br />&lt;init-param&gt;<br />&lt;param-name&gt;E-mail&lt;/param-name&gt;<br />&lt;param-value&gt;Tommy@163.com&lt;/param-value&gt;<br />&lt;/init-param&gt;<br />&lt;/servlet&gt;<br />经过上面的配置，在servlet中能够调用getServletConfig().getInitParameter("param1")获得参数名对应的值。</p>
<p>4、指定错误处理页面，可以通过&#8220;异常类型&#8221;或&#8220;错误码&#8221;来指定错误处理页面。<br />&lt;error-page&gt;<br />&lt;error-code&gt;404&lt;/error-code&gt;<br />&lt;location&gt;/error404.jsp&lt;/location&gt;<br />&lt;/error-page&gt;<br />-----------------------------<br />&lt;error-page&gt;<br />&lt;exception-type&gt;java.lang.Exception&lt;exception-type&gt;<br />&lt;location&gt;/exception.jsp&lt;location&gt;<br />&lt;/error-page&gt;</p>
<p>5、设置过滤器：比如设置一个编码过滤器，过滤所有资源<br />&lt;filter&gt;<br />&lt;filter-name&gt;XXXCharaSetFilter&lt;/filter-name&gt;<br />&lt;filter-class&gt;net.test.CharSetFilter&lt;/filter-class&gt;<br />&lt;/filter&gt;<br />&lt;filter-mapping&gt;<br />&lt;filter-name&gt;XXXCharaSetFilter&lt;/filter-name&gt;<br />&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />&lt;/filter-mapping&gt;</p>
<p>6、设置监听器：<br />&lt;listener&gt;<br />&lt;listener-class&gt;net.test.XXXLisenet&lt;/listener-class&gt;<br />&lt;/listener&gt;</p>
<p>7、设置会话(Session)过期时间，其中时间以分钟为单位，假如设置60分钟超时：<br />&lt;session-config&gt;<br />&lt;session-timeout&gt;60&lt;/session-timeout&gt;<br />&lt;/session-config&gt;</p>
<p>除了这些标签元素之外，还可以往web.xml中添加那些标签元素呢，那些标签元素都能起什么作用呢？我们只要去查看web.xml的模式文件就能知道。直接看模式文件看不懂，可以找一些中文教程来看看。</p><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388072.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-19 15:15 <a href="http://www.blogjava.net/baizhihui19870626/articles/388072.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>why在重写equals时还必须重写hashcode方法</title><link>http://www.blogjava.net/baizhihui19870626/articles/388065.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Wed, 19 Sep 2012 06:20:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388065.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388065.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388065.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388065.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388065.html</trackback:ping><description><![CDATA[<p align="left">&nbsp;</p>
<div id="cnblogs_post_body">
<p>首先我们先来看下String类的源码：可以发现String是重写了Object类的equals方法的，并且也重写了hashcode方法</p>
<div class="cnblogs_code">
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a title="复制代码" href="javascript:void(0);"><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></a></span></div><pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">boolean</span><span style="color: #000000"> equals(Object anObject) {
    </span><span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span> ==<span style="color: #000000"> anObject) {
        </span><span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span><span style="color: #000000">;
    }
    </span><span style="color: #0000ff">if</span> (anObject <span style="color: #0000ff">instanceof</span><span style="color: #000000"> String) {
        String anotherString </span>=<span style="color: #000000"> (String)anObject;
        </span><span style="color: #0000ff">int</span> n =<span style="color: #000000"> count;
        </span><span style="color: #0000ff">if</span> (n ==<span style="color: #000000"> anotherString.count) {
        </span><span style="color: #0000ff">char</span> v1[] =<span style="color: #000000"> value;
        </span><span style="color: #0000ff">char</span> v2[] =<span style="color: #000000"> anotherString.value;
        </span><span style="color: #0000ff">int</span> i =<span style="color: #000000"> offset;
        </span><span style="color: #0000ff">int</span> j =<span style="color: #000000"> anotherString.offset;
        </span><span style="color: #0000ff">while</span> (n-- != 0<span style="color: #000000">) {
            </span><span style="color: #0000ff">if</span> (v1[i++] != v2[j++<span style="color: #000000">])
            </span><span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span><span style="color: #000000">;
        }
        </span><span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span><span style="color: #000000">;
        }
    }
    </span><span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span><span style="color: #000000">;
    }


</span><span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span><span style="color: #000000"> hashCode() {
    </span><span style="color: #0000ff">int</span> h =<span style="color: #000000"> hash;
    </span><span style="color: #0000ff">if</span> (h == 0<span style="color: #000000">) {
        </span><span style="color: #0000ff">int</span> off =<span style="color: #000000"> offset;
        </span><span style="color: #0000ff">char</span> val[] =<span style="color: #000000"> value;
        </span><span style="color: #0000ff">int</span> len =<span style="color: #000000"> count;

            </span><span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; len; i++<span style="color: #000000">) {
                h </span>= 31*h + val[off++<span style="color: #000000">];
            }
            hash </span>=<span style="color: #000000"> h;
        }
        </span><span style="color: #0000ff">return</span><span style="color: #000000"> h;
    }</span></pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a title="复制代码" href="javascript:void(0);"><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></a></span></div></div>
<p>那为什么在重写equals方法时都要重写equals方法呢：<br />首先equals与hashcode间的关系是这样的：</p>
<p>1、如果两个对象相同（即用equals比较返回true），那么它们的hashCode值一定要相同；</p>
<p>2、如果两个对象的hashCode相同，它们并不一定相同(即用equals比较返回false) </p>
<p>自我的理解：由于为了提高程序的效率才实现了hashcode方法，先进行hashcode的比较，如果不同，那没就不必在进行equals的比较了，这样就大大减少了equals比较的</p>
<p>次数，这对比需要比较的数量很大的效率提高是很明显的，一个很好的例子就是在集合中的使用；</p>
<p>我们都知道java中的List集合是有序的，因此是可以重复的，而set集合是无序的，因此是不能重复的，那么怎么能保证不能被放入重复的元素呢，但靠equals方法一样比较的</p>
<p>话，如果原来集合中以后又10000个元素了，那么放入10001个元素，难道要将前面的所有元素都进行比较，看看是否有重复，欧码噶的，这个效率可想而知，因此hashcode</p>
<p>就应遇而生了，java就采用了hash表，利用哈希算法（也叫散列算法），就是将对象数据根据该对象的特征使用特定的算法将其定义到一个地址上，那么在后面定义进来的数据</p>
<p>只要看对应的hashcode地址上是否有值，那么就用equals比较，如果没有则直接插入，只要就大大减少了equals的使用次数，执行效率就大大提高了。</p>
<p>继续上面的话题，为什么必须要重写hashcode方法，其实简单的说就是为了保证同一个对象，保证在equals相同的情况下hashcode值必定相同，如果重写了equals而未重写</p>
<p>hashcode方法，可能就会出现两个没有关系的对象equals相同的（因为equal都是根据对象的特征进行重写的），但hashcode确实不相同的</p></div>
<p align="left">&nbsp;</p><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388065.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-19 14:20 <a href="http://www.blogjava.net/baizhihui19870626/articles/388065.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Vector和ArrayList区别   Hashtable和HashMap区别  ArrayList和LinkedList区别</title><link>http://www.blogjava.net/baizhihui19870626/articles/388061.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Wed, 19 Sep 2012 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388061.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388061.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388061.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388061.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388061.html</trackback:ping><description><![CDATA[<p style="text-align: left; padding-bottom: 0px; border-right-width: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; orphans: 2; border-top-width: 0px; border-bottom-width: 0px; color: rgb(73,73,73); word-break: normal; border-left-width: 0px; word-spacing: 0px; padding-top: 0px; border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><font style="line-height: 36px; word-wrap: normal; word-break: normal" color="#ff0000" size="5">Vector和ArrayList区别</font><br />Vector和ArrayList Vector和ArrayList在使用上非常相似,都可用来表示一组数量可变的对象应用的集合,并且可以随机地访问其中的元素。<br />Vector的方法都是同步的(Synchronized),是线程安全的(thread-safe)，而ArrayList的方法不是，<br />由于线程的同步必然要影响性能，因此,<br />ArrayList的性能比Vector好。<br />当Vector或ArrayList中的元素超过它的初始大小时,Vector会将它<br />的容量翻倍,而ArrayList只增加50%的大小，这样,ArrayList就有利<br />于节约内存空间。<br /><font style="line-height: 36px; word-wrap: normal; word-break: normal" color="#ff0000" size="5">Hashtable和<font style="line-height: 36px; word-wrap: normal; word-break: normal" color="#ff0000">HashMap区别</font></font></p>
<p style="text-align: left; padding-bottom: 0px; border-right-width: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; orphans: 2; border-top-width: 0px; border-bottom-width: 0px; color: rgb(73,73,73); word-break: normal; border-left-width: 0px; word-spacing: 0px; padding-top: 0px; border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">a.Hashtable是继承自陈旧的Dictionary类的，HashMap继承自AbstractMap类同时是Java 1.2引进的Map接口的一个实现。<br />　　b.也许最重要的不同是Hashtable的方法是同步的，而HashMap的方法不是。这就意味着，然你可以不用采取任何特殊的行为就可以在一个 多线程的应用程序中用一个Hashtable，但你必须同样地为一个HashMap提供外同步。一个方便的方法就是利用Collections类的静态的synchronizedMap()方法，它创建一个线程安全的Map对象，并把它作为一个封装的对象来返回。这个对象的方法可以让你同步访问潜在的HashMap。这么做的结果就是当你不需要同步时，你不能切断Hashtable中的同步（比如在一个单线程的应用程序中），而且同步增加了很多处理费用。<br />　　c.第三点不同是，只有HashMap可以让你将空值作为一个表的条目的key或value。HashMap中只有一条记录可以是一个空的key，但任意数量的条目可以是空的value。这就是说，如果在表中没有发现搜索键，或者如果发现了搜索键，但它是一个空的值，那么get()将返回null。如果有必要，用containKey()方法来区别这两种情况。<br />　　d.HashMap去掉了Hashtable的contains方法，保留了containsValue和containsKey方法<br />　　e.Hashtable中hash数组默认大小是11，增加的方式是 old*2+1。HashMap中hash数组的默认大小是16，而且一定是2的指数<br /><br /><font style="line-height: 36px; word-wrap: normal; word-break: normal" color="#ff0000" size="5">ArrayList和LinkedList区别</font><br />对于处理一列数据项,Java提供了两个类ArrayList和LinkedList,ArrayList的内部实现是基于内部数组Object[],所以从概念上讲,它更象数组，但LinkedList的内部实现是基于一组连接的记录,所以,它更象一个链表结构，所以,它们在性能上有很大的差别。<br />从上面的分析可知,在ArrayList的前面或中间插入数据时,你必须将其后的所有数据相应的后移,这样必然要花费较多时间，所以,当你的操作是在一列数据的后面添加数据而不是在前面或中间,并且需要随机地访问其中的元素时,使用ArrayList会提供比较好的性能<br />而访问链表中的某个元素时,就必须从链表的一端开始沿着连接方向一个一个元素地去查找,直到找到所需的元素为止，所以,当你的操作是在一列数据的前面或中间添加或删除数据,并且按照顺序访问其中的元素时,就应该使用LinkedList了。<br />如果在编程中,1，2两种情形交替出现,这时,你可以考虑使用List这样的通用接口,而不用关心具体的实现，在具体的情形下,它的性能由具体的实现来保证。<br /><font style="line-height: 21px; word-wrap: normal; word-break: normal" color="#ff0000">配置集合类的初始大小</font><br />在Java集合框架中的大部分类的大小是可以随着元素个数的增加而相应的增加的，我们似乎不用关心它的初始大小,但如果我们考虑类的性能问题时,就一定要考虑尽可能地设置好集合对象的初始大小,这将大大提高代码的性能。<br />比如,Hashtable缺省的初始大小为101,载入因子为0.75,即如果其中的元素个数超过75个,它就必须增加大小并重新组织元素，所以,如果你知道在创建一个新的Hashtable对象时就知道元素的确切数目如为110,那么,就应将其初始大小设为110/0.75=148,这样,就可以避免重新组织内存并增加大小</p><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388061.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-19 13:51 <a href="http://www.blogjava.net/baizhihui19870626/articles/388061.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java中字符集的问题 </title><link>http://www.blogjava.net/baizhihui19870626/articles/388054.html</link><dc:creator>小白19870626</dc:creator><author>小白19870626</author><pubDate>Wed, 19 Sep 2012 03:33:00 GMT</pubDate><guid>http://www.blogjava.net/baizhihui19870626/articles/388054.html</guid><wfw:comment>http://www.blogjava.net/baizhihui19870626/comments/388054.html</wfw:comment><comments>http://www.blogjava.net/baizhihui19870626/articles/388054.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/baizhihui19870626/comments/commentRss/388054.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baizhihui19870626/services/trackbacks/388054.html</trackback:ping><description><![CDATA[<p><span style="font-size: 18px">1、JVM中单个字符占用的字节长度跟编码方式有关，而默认编码方式又跟平台是一一对应的或说平台决定了默认字符编码方式；</span></p>
<p><span style="font-size: 18px">2、<strong><span style="color: #ff0000">对于单个字符：ISO-8859-1单字节编码，GBK双字节编码，UTF-8三字节编码</span></strong>；<strong><span style="color: #ff0000">因此中文平台(中文平台默认字符集编码GBK)下一个中文字符占2个字节，而英文平台(英文平台默认字符集编码Cp1252(类似于ISO-8859-1))。</span></strong></span></p>
<p><span style="font-size: 18px">3、<strong>g<span style="color: #ff0000">etBytes()、getBytes(encoding)函数的作用是使用系统默认或者指定的字符集编码方式，将字符串编码成字节数组</span>。</strong></span></p>
<p><span style="font-size: 18px">编码方式决定字节长度；<strong><span style="background-color: rgb(255,255,255); color: #ff0000">在中文平台下，默认的字符集编码是GBK</span></strong><span style="color: #ff0000">，</span>此时如果使用getBytes()或getBytes("GBK")，<strong><span style="color: #ff0000">则按照GBK的编码规则将每个中文字符用2个byte表示</span></strong>。<strong><span style="color: #ff0000">所以我们看到"中文"最终GBK编码结果就是： -42 -48 -50 -60 。-42和-48代表了"中"字，而"-50"和"-60"则代表了"文"字。</span></strong></span></p>
<p><span style="font-size: 18px">在中文平台下，<span style="background-color: rgb(255,255,255)"><span style="color: #ff0000">如果指定的字符集编码是UTF-8，那么按照UTF-8对中文的编码规则：每个中文用3个字节表示，那么"中文"这两个字符最终被编码成：-28 -72 -83、-26 -106 -121两组。每3个字节代表一个中文字符。</span></span></span></p>
<p><span style="font-size: 18px"><span style="background-color: rgb(255,255,255)"><span style="color: #ff0000"><strong>在中文平台下，如果指定的字符集编码是ISO-8859-1，由于此字符集是单字节编码，所以使用getBytes("ISO-8859-1")时，每个字符只取一个字节，每个汉字只取到了一半的字符。另外一半的字节丢失了。由于这一半的字符在字符集中找不到对应的字符，所以默认使用编码63代替，也就是?。</strong></span></span></span></p>
<p><span style="font-size: 18px"><strong><span style="color: #ff0000">在英文平台下，默认的字符集编码是Cp1252(类似于ISO-8859-1</span></strong>)，<strong><span style="color: #ff0000">如果使用GBK、UTF-8进行编码，得到的字节数组依然是正确的(GBK4个字节，UTF-8是6个字节)。因为在JVM内部是以Unicode存储字符串的，使用getBytes(encoding)会让JVM进行一次Unicode到指定编码之间的转换。</span></strong>对于GBK，JVM依然会转换成4个字节，对于UTF-8，JVM依然会转换成6个字节。<strong><span style="color: #ff0000">但是对于ISO-8859-1，则由于无法转换(2个字节---&gt;1个字节，截取了一半的字节)，所以转换后的结果是错误的。</span></strong></span></p>
<p><span style="font-size: 18px"><span style="font-weight: bold"><span style="color: #ff0000"></span></span></span></p>
<p><span style="font-size: 18px">在中文平台下，默认的字符集编码是GBK，于是content.getBytes()得到的是什么呢？就是下面这4个字节：</span></p>
<p><span style="font-size: 18px">byte[0] </span><span style="font-size: 18px"></span><span style="font-size: 18px">= -42 hex string = ffffffd6</span></p>
<p><span style="font-size: 18px">byte[1] = -48 hex string = ffffffd0 </span></p>
<p><span style="font-size: 18px">byte[2] = -50 hex string = ffffffce</span></p>
<p><span style="font-size: 18px">byte[3] = -60 hex string = ffffffc4</span></p>
<p><span style="font-size: 18px">如果新的encoding是GBK，那么经过解码后，由于一个字符用2个字节表示。于是最终的结果就是：</span></p>
<p><span style="font-size: 18px">char[0]='中' --- byte[0] + byte[1]</span></p>
<p><span style="font-size: 18px">char[1]='文' --- byte[2] + byte[3]</span></p>
<p><span style="font-size: 18px">如果新的encoding是ISO-8859-1，那么经过解码后，由于一个字符用1个字节表示，于是原来本应该2个字节一起解析的变成单个字节解析，每个字节都代表了一个汉字字符的一半。这一半的字节在ISO-8859-1中找不到对应的字符，就变成了"?"了，最终的结果：</span></p>
<p><span style="font-size: 18px">char[0]='?' ---- byte[0] </span></p>
<p><span style="font-size: 18px">char[1]='?' ---- byte[1] </span></p>
<p><span style="font-size: 18px">char[2]='?' ---- byte[2]</span></p>
<p><span style="font-size: 18px">char[3]='?' ---- byte[3]</span></p>
<p><span style="font-size: 18px">如果新的encoding是UTF-8，那么经过解码后，由于一个字符用3个字节表示，于是原来4个字节的数据无法正常的解析成UTF-8的数据，最终的结果也是每一个都变成"?"。</span></p>
<p><span style="font-size: 18px">char[0]='?' ---- byte[0]</span></p>
<p><span style="font-size: 18px">char[1]='?' ---- byte[1]</span></p>
<p><span style="font-size: 18px">char[2]='?' ---- byte[2] </span></p>
<p><span style="font-size: 18px">char[3]='?' ---- byte[3]</span></p>
<p><span style="font-size: 18px">如果是在英文平台下，由于默认的编码方式是Cp1252，于是content.getBytes()得到的字节都是被截去一半的残留字符，所以我们看到在英文平台下，不论指定的encoding是GBK、UTF-8，其结果和ISO-8859-1都是一样的。</span></p>
<p><span style="font-size: 18px"><strong><span style="color: #ff0000">记住：这个方法再次证明了String的getBytes()方法的危险性，如果我们使用new String(str.getBytes(), encoding)对字符串进行重新编码解码时，我们一定要清楚str.getBytes()方法返回的字节数组的长度、内容到底是什么，因为在接下来使用新的encoding进行编码解码时，Java并不会自动地对字节数组进行扩展以适应新的encoding。而是按照新的编码方法直接对该字节数组进行解析。</span></strong>于是结果就像上面的例子一样，同样是4个原始字节，有些每2个一组进行解析，有些每个一组进行解析，有些每3个一组进行解析。其结果就只能看那种编码方式合适了。</span></p><br />
<p><span style="font-size: 18px"><span style="background-color: rgb(255,255,255)"><span style="color: #ff0000"><strong>结论：</strong></span></span>相同的平台下，同一个中文字符，在不同的编码方式下，得到的是完全不同的字节数组。这些字节数组有可能是正确的(只要该字符集支持中文)，也可能是完全错误的(该字符集不支持中文)。</span></p>
<p><span style="font-size: 18px"><strong><span style="color: #ff0000">记住：不要轻易地使用或滥用String类的getBytes(encoding)方法，更要尽量避免使用getBytes()方法。因为这个方法是平台依赖的，在平台不可预知的情况下完全可能得到不同的结果</span></strong>。<strong><span style="color: #ff0000">如果一定要进行字节编码，则用户要确保encoding的方法就是当初字符串输入时的encoding。</span></strong></span></p>
<p><span style="font-size: 18px">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 18px"><strong><span style="color: #ff0000">和getBytes(encoding)不同，toCharArray()返回的是"自然字符"。但是这个"自然字符"的数目和内容却是由原始的编码方式决定的</span></strong>。</span></p>
<p><span style="font-size: 18px"></span></p>
<p><span style="font-size: 18px">FileWriter是字符流输出流，而OutputStreamWriter是字节流输出流在中文平台下，<strong><span style="color: #ff0000">如果使用FileWriter，不论你如何设置字符集都不会起作用。因为它采用的是默认的系统字符集。即便你设置了System.setProperty("file.encoding", "ISO-8859-1")，或者在运行时给予参数-Dfile.encoding=UTF-8都不会起作用。你会发现它最终还是都已"GB2312"或者"GBK"的方式保存。</span></strong></span></p>
<p><span style="font-size: 18px">在中文平台下，如果使用OutputStreamWriter，则在后台写入时会把字符流转换成字节流，此时指定的编码字符集就起作用了。可以看到在指定GBK、UTF-8的情况下中文可以正常的保存和读取，同时文件按照我们给定的方式保存了。而对于ISO-8859-1则变成了?，这<strong><span style="color: #ff0000">再次证明了采用ISO-8859-1是不能保存中文的，而且会因为中文编码在ISO-8859-1的编码中找不到对应的字符而默认转换成?。</span></strong></span></p>
<p><span style="font-size: 18px">在英文平台下，如果使用FileWriter，不论你如何设置字符集同样都不会起作用。所有的文件都将按照ISO-8859-1的编码方式保存，毫无疑问地变成了?。在英文平台下，如果使用OutputStreamWriter，则只有当我们把字符和文件的编码方式正确设置为GBK、UTF-8的情况下，中文才能正确的保存并显示。</span></p>
<p><span style="font-size: 18px">通过上述的实验证明，<strong><span style="color: #ff0000">为了确保在不同的平台下，客户端输入的中文可以被正确地解析、保存、读取。最好的办法就是使用OutputStreamWriter配合UTF-8编码。</span></strong>如果不想使用UTF-8编码，那么可以考虑使用GB2312，不建议使用GBK、GB18030。因为对于某些老式的文本编辑器，甚至不支持GBK、GB18030的编码，但是对于GB2312则是一定支持的。因为前两者都不是国标但后者是。</span></p>
<p><span style="font-size: 18px">关于String的getBytes()，getBytes(encoding)和new String(bytes, encoding)这三个方法，非常值得注意：A.getBytes()：使用平台默认的编码方式(通过file.encoding属性获取)方式来将字符串转换成byte[]。得到的是字符串最原始的字节编码值。</span></p>
<p><span style="font-size: 18px">B.getBytes(NAME_OF_CHARSET)：<strong><span style="color: #ff0000">使用指定的编码方式将字符串转换成byte[]，如果想要得到正确的字节数组，程序员必须给出正确的NAME_OF_CHARSET</span></strong>。否则得到的就不会得到正确的结果。</span></p>
<p><span style="font-size: 18px">C.new String(bytes, encoding)：<strong><span style="color: #ff0000">如果我们在客户端使用UTF-8编码的JSP页面发出请求，浏览器编码后的UTF-8字节会以ISO-8859-1的形式传递到服务器端。所以要得到经HTTP协议传输的原始字节，我们需要先调用getBytes("ISO-8859-1")得到原始的字节，但由于我们客户端的原始编码是UTF-8，如果继续按照ISO-8859-1解码，那么得到的将不是一个中文字符，而是3个乱码的字符。所以我们需要再次调用new String(bytes,"UTF-8")，将字节数组按照UTF-8的格式，每3个一组进行解码，才能还原为客户端的原始字符。</span></strong></span></p>
<p><span style="font-size: 18px">D.String的getBytes()、getBytes(NAME_OF_CHARSET)方法都是比较微妙的方法，原则上：传输时采用的是什么编码，我们就需要按照这种编码得到字节。new String(bytes, NAME_OF_CHARSET)则更加需要小心，原则上：客户端采用的是什么编码，那么这里的NAME_OF_CHARSET就必须和客户端保持一致。<strong><span style="color: #3333ff">例如JSP页面是GBK，那么我们接收页面传递而来的参数时就必须使用new String(parameter.getBytes("ISO-8859-1"), "GBK")</span></strong>;如果使用了错误的解码方式，如使用了UTF-8，那么得到的很有可能就是乱码了。也就是说：GBK---&gt;ISO-8859-1---&gt;GBK、UTF-8---&gt;ISO-8859-1---&gt;UTF-8的转换过程是没有问题的。但是GBK---&gt;ISO-8859-1---&gt;UTF-8、UTF-8---&gt;ISO-8859-1---&gt;GBK的字节直接转码则可能导致乱码，需要另外的转换过程。</span></p>
<p><span style="font-size: 18px"><strong><span style="color: #ff0000">记住：</span></strong>谨慎地使用getBytes(NAME_OF_CHARSET)和new String(bytes, NAME_OF_CHARSET)，除非你很清楚的知道原始的字符编码和传输协议使用的编码。推荐使用基于服务器的配置、过滤器设置request/response的characterEncoding、content type属性。还有就是JSP页面的pageEncoding属性、HTML meta元素的content type属性。尽量避免频繁的在代码中进行字符串转码，即降低了效率又增加了风险。</span></p>
<p><span style="font-size: 18px">问题：我们在web应用开发过程中经常遇到输出某种编码的字符，如iso8859-1等，如何输出一个某种编码的字符串？</span></p><span style="font-size: 18px">代码如下：</span> 
<div class="dp-highlighter bg_java">
<div class="bar">
<div class="tools"><strong>[java]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/kiss_the_sun/article/details/7852724#"><u><font color="#0066cc">view plain</font></u></a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/kiss_the_sun/article/details/7852724#"><u><font color="#0066cc">copy</font></u></a><a class="PrintSource" title="print" href="http://blog.csdn.net/kiss_the_sun/article/details/7852724#"><u><font color="#0066cc">print</font></u></a><a class="About" title="?" href="http://blog.csdn.net/kiss_the_sun/article/details/7852724#"><u><font color="#0066cc">?</font></u></a></div></div>
<ol class="dp-j"><li class="alt"><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> StringTest { </span></li><li><span></span><span class="keyword">public</span><span> </span><span class="keyword">static</span><span> </span><span class="keyword">void</span><span> main(String[] args){ </span></span></li><li class="alt"><span>String str=</span><span class="string">"我是中国人"</span><span>; </span></span></li><li><span></span><span class="keyword">try</span><span> { </span></span></li><li class="alt"><span></span><span class="keyword">byte</span><span>[] by=str.getBytes(</span><span class="string">"ISO-8859-1"</span><span>); </span></span></li><li><span></span><span class="keyword">byte</span><span>[] by1=str.getBytes(</span><span class="string">"GBK"</span><span>); </span></span></li><li class="alt"><span></span><span class="keyword">byte</span><span>[] by2=str.getBytes(</span><span class="string">"utf-8"</span><span>); </span></span></li><li><span>System.out.println(</span><span class="string">"ISO-8859-1"</span><span>); </span></span></li><li class="alt"><span>System.out.println(by.length); </span></li><li><span>System.out.println(by[</span><span class="number">0</span><span>]); </span></span></li><li class="alt"><span></span></li><li><span>System.out.println(</span><span class="string">"GBK"</span><span>); </span></span></li><li class="alt"><span>System.out.println(by1.length); </span></li><li><span>System.out.println(by1[</span><span class="number">0</span><span>]); </span></span></li><li class="alt"><span></span></li><li><span>System.out.println(</span><span class="string">"utf-8"</span><span>); </span></span></li><li class="alt"><span>System.out.println(by2.length); </span></li><li><span>System.out.println(by2[</span><span class="number">0</span><span>]); </span></span></li><li class="alt"><span></span></li><li><span></span><span class="comment">//先将字符串以ISO-8859-1进行编码 </span><span></span></span></li><li class="alt"><span>String tempStr = </span><span class="keyword">new</span><span> String(str.getBytes(), </span><span class="string">"ISO-8859-1"</span><span>); </span></span></li><li><span></span><span class="comment">//由于中文平台一个中文占两上字节，所以以ISO-8859-1进行编码时，输出为10个字符的乱码 </span><span></span></span></li><li class="alt"><span>System.out.println(tempStr); </span></li><li><span></span><span class="comment">//再获取该字符串的ISO-8859-1字节，以GBK解码， </span><span></span></span></li><li class="alt"><span>tempStr=</span><span class="keyword">new</span><span> String(tempStr.getBytes(</span><span class="string">"ISO-8859-1"</span><span>),</span><span class="string">"GBK"</span><span>); </span></span></li><li><span></span><span class="comment">//还原 </span><span></span></span></li><li class="alt"><span>System.out.println(tempStr); </span></li><li><span>} </span></li><li class="alt"><span></span><span class="keyword">catch</span><span> (Exception e) { </span></span></li><li><span>System.err.println(e.getMessage()); </span></li><li class="alt"><span>} </span></li><li><span>} </span></li><li class="alt"><span>} </span></li></ol></div><br />输出： <pre style="padding-bottom: 0px; line-height: 22px; background-color: rgb(255,252,246); margin-top: 0px; padding-left: 0px; padding-right: 0px; zoom: 1; font-family: Arial; word-wrap: break-word; white-space: pre-wrap; margin-bottom: 10px; font-size: 14px; padding-top: 0px" id="best-answer-content" class="reply-text mb10" name="code">GBK
10
-50
utf-8
15
-26
???????&#250;??
我是中国人
</pre><img src ="http://www.blogjava.net/baizhihui19870626/aggbug/388054.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baizhihui19870626/" target="_blank">小白19870626</a> 2012-09-19 11:33 <a href="http://www.blogjava.net/baizhihui19870626/articles/388054.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>