??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产日韩在线,国产高清一区视频,精品欧美一区二区三区精品久久http://www.aygfsteel.com/lazing/Future network: Share and Create...zh-cnSat, 17 May 2025 17:33:55 GMTSat, 17 May 2025 17:33:55 GMT60使用XFire与Spring开发Web Servicehttp://www.aygfsteel.com/lazing/archive/2007/08/16/xfire_spring_web_service.htmlHIMMELHIMMELThu, 16 Aug 2007 05:15:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/08/16/xfire_spring_web_service.htmlhttp://www.aygfsteel.com/lazing/comments/137198.htmlhttp://www.aygfsteel.com/lazing/archive/2007/08/16/xfire_spring_web_service.html#Feedback10http://www.aygfsteel.com/lazing/comments/commentRss/137198.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/137198.html使用XFire与Spring开发Web Service

源代码下载(三个样例工程Maven版本Q?xfire-src.zip

相关lib文g请到XFire官方|站Q见参考) 下蝲发布版本?/p>

PDF版本下蝲

目录
实现功能与特? 2

q行环境 2

开发^? 2

实施步骤 2

概述 2

新徏Java Project 3

新徏WTP动态WEB工程 4

实现服务 6

利用Spring、XFire装配与暴露服? 7

试q访问服? 7

利用XFire实现客户? 10

扩展主题 11

利用MTOM传输二进制对象(文gQ? 11

附录 12

XFire在WebLogic 8.1中的配置 12

参? 12

实现功能与特?/h1>
  • ZJ2EEq_的Web Service服务
  • 开发方便,配置?
    • 设计接口
    • 实现服务
    • 配置暴露接口
    • XFire自动生成对应的wsdl
    • 支持高详细配置
  • 与Spring无缝集成

q行环境

开发^?/h1>

实施步骤

概述

  1. 建立一个Java Project用于Domain实体和Web Service接口Q这个工E的输出是一个jar包,为Web Service工程和Web Service Client׃n?/li>
  2. 建立WTP动态WEB工程部vWeb Service
  3. 建立Java Project使用Web Service (Web Service Client)

新徏Java Project

  1. 建立普通Java Project 以下UCؓcommon工程
  2. 如果使用MavenQ项目依?/li>

<dependency>

<groupId>javax.mail</groupId>

<artifactId>mail</artifactId>

<version>1.4</version>

</dependency>

  1. 普通情况需要加入如下lib

activation-1.1.jar

mail-1.4.jar

  1. ~写c?org.ave7.xfire.domain.User

org.ave7.xfire.domain.User.java

package org.ave7.xfire.domain;

import java.io.Serializable;

import java.util.Date;

public class User implements Serializable {

private static final long serialVersionUID = 6517808321041980976L;

private Long userId;

private String accountId;

private String userName;

private Date lastLogin;

public String getAccountId() {

return accountId;

}

public void setAccountId(String accountId) {

this.accountId = accountId;

}

public Date getLastLogin() {

return lastLogin;

}

public void setLastLogin(Date lastLogin) {

this.lastLogin = lastLogin;

}

public Long getUserId() {

return userId;

}

public void setUserId(Long userId) {

this.userId = userId;

}

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

}

  1. ~写接口 org.ave7.xfire.ws.UserService
org.ave7.xfire.ws.UserService.java

package org.ave7.xfire.ws;

import org.ave7.xfire.domain.User;

public
interface UserService {

public User queryUserByAccoutId(String accountId);

public
void createUser(User user);

}

新徏WTP动态WEB工程

  1. 配置WTP加入Tomcat Server Runtime
    1. 选择Windows -> Preference
    2. 在左侧选择Server->Installed Runtime dTomcat
  2. 新徏工程Q选择Dynamic Web Project 输入Project Name: XFireService
  3. 讄q行环境为Dynamic Web Module 2.3 , JDK 1.4
  4. 如果需要结合MavenQ请如下配置Q否则用默认即?br>
  5. 如果使用Mavenh入如下依赖以及之前的Common工程Q否则根据后面的列表复制lib文g到对应目?/li>

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-aegis</artifactId>

<version>1.2.4</version>

</dependency>

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-spring</artifactId>

<version>1.2.4</version>

<dependency>

<groupId>xalan</groupId>

<artifactId>xalan</artifactId>

<version>2.7.0</version>

</dependency>


Lib文g列表

xbean-2.2.0.jar

qdox-1.5.jar

commons-attributes-api-2.1.jar

ant-1.5.jar

wstx-asl-3.2.0.jar

stax-utils-20040917.jar

commons-httpclient-3.0.jar

spring-1.2.6.jar

XmlSchema-1.1.jar

stax-api-1.0.1.jar

jaxen-1.1-beta-9.jar

xfire-annotations-1.2.4.jar

xfire-aegis-1.2.4.jar

xfire-core-1.2.4.jar

xfire-spring-1.2.4.jar

xfire-xmlbeans-1.2.4.jar

jdom-1.0.jar

xbean-spring-2.7.jar

wsdl4j-1.6.1.jar

commons-beanutils-1.7.0.jar

activation-1.1.jar

mail-1.4.jar

commons-codec-1.3.jar

xmlParserAPIs-2.6.2.jar

xercesImpl-2.6.2.jar

junit-3.8.1.jar

commons-logging-1.0.4.jar
xalan-2.7.0.jar

实现服务

org.ave7.xfire.ws.UserServiceImpl.java

package org.ave7.xfire.ws;

import java.rmi.RemoteException;

import java.util.Date;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.ave7.xfire.domain.User;

public
class UserServiceImpl implements UserService {

private
static
final Log log = LogFactory.getLog(UserServiceImpl.class);

public
void createUser(User user) throws RemoteException {

log.debug(“createUser user
=” + user);

}

public User queryUserByAccoutId(String accountId) throws
RemoteException {

log.debug(“accountId
=” + accountId);

User user 
= new User();

user.setAccountId(“testAccount”);

user.setLastLogin(
new Date());

user.setUserName(“试用户“);

user.setUserId(
new Long(123L));

return user;

}

}

利用Spring、XFire装配与暴露服?/h2>
  1. 在web.xml配置相关lg
<?xml version=“1.0″ encoding=“UTF-8″?>

<!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”
>

<web-app id=“WebApp_ID”>

<display-name>XFireService</display-name>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext*.xml</param-value>

</context-param>

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

<servlet>

<servlet-name>xfire</servlet-name>

<servlet-class>

org.codehaus.xfire.spring.XFireSpringServlet

</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>xfire</servlet-name>

<url-pattern>/service/*</url-pattern>

</servlet-mapping>

</web-app>

  1. 在applicationContext.xml配置相关服务
<?xml version=“1.0″ encoding=“UTF-8″?>

<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN”

“http://www.springframework.org/dtd/spring-beans.dtd”
>

<beans>

<import resource=“classpath:org/codehaus/xfire/spring/xfire.xml” />

<bean id=“baseWebService”

class=“org.codehaus.xfire.spring.remoting.XFireExporter”

lazy-init=“false” abstract=“true”>

<property name=“serviceFactory” ref=“xfire.serviceFactory” />

<property name=“xfire” ref=“xfire” />

</bean>

<bean id=“userWS” class=“org.ave7.xfire.ws.UserServiceImpl”></bean>

<bean id=“userService” parent=“baseWebService”>

<property name=“serviceBean” ref=“userWS” />

<property name=“serviceClass”

value=“org.ave7.xfire.ws.UserService” />

</bean>

</beans>

试q访问服?/h2>
  1. 查lib文g夹,Maven用户注意d对common工程的依赖,其他情况hcommon工程导出的jar包复制到web-inf/lib目录
  2. 在WTP中添加服务器Q部|应?br>
  3. 在浏览器中输入类?http://localhost:8080/XFireService/service 应看?br>
  4. 点击wsdl http://localhost:8080/XFireService/service/UserService?wsdl 看到

    如果q一步出?00错误Q请查是否有xalan.jar?/li>
  5. 在WTP中利用Web Service Explore试SOAP方式Q在WTP工具栏选择 最右侧按钮
  6. 点击右上角进入WSDL page
  7. 点击WSDL Main节点输入服务wsdl地址Q点?br>
  8. 列出所有的可用服务Q选择服务试
  9. 试queryUserByAccountId
  10. 点击l果中的Source可以看到SOAP报文

利用XFire实现客户?/h2>
  1. 新徏一个普通Java工程Qlib中引用XFire相关?/li>

如果使用Mavend如下依赖以及对common工程的引?/p>

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-aegis</artifactId>

<version>1.2.4</version>

</dependency>

普通Java工程d如下lib以及对common工程的引?/p>

activation-1.1.jar

commons-codec-1.3.jar

commons-httpclient-3.0.jar

commons-logging-1.0.4.jar

jaxen-1.1-beta-9.jar

jdom-1.0.jar

junit-3.8.1.jar

mail-1.4.jar

stax-api-1.0.1.jar

stax-utils-20040917.jar

wsdl4j-1.6.1.jar

wstx-asl-3.2.0.jar

xercesImpl-2.6.2.jar

xfire-aegis-1.2.4.jar

xfire-core-1.2.4.jar

xmlParserAPIs-2.6.2.jar

XmlSchema-1.1.jar

  1. ~写客户端程?/li>

org.ave7.xfire.client.MyClient.java

package org.ave7.xfire.client;

import java.net.MalformedURLException;

import java.rmi.RemoteException;

import org.ave7.xfire.domain.User;

import org.ave7.xfire.ws.UserService;

import org.codehaus.xfire.client.XFireProxyFactory;

import org.codehaus.xfire.service.Service;

import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public
class MyClient {

public
static
void main(String[] args) {

try {

Service serviceModel 
= new ObjectServiceFactory()

.create(UserService.
class);

UserService service 
= (UserService) new XFireProxyFactory().create(

serviceModel,

“http:
//localhost:8080/XFireService/service/UserService”);

User user 
= service.queryUserByAccoutId(“123″);

System.out

.println(“userId
=” + user.getUserId() + “, userName=

+ user.getUserName() + “, lastLogin=

+ user.getLastLogin());

catch (MalformedURLException e) {

e.printStackTrace();

catch (RemoteException e) {

e.printStackTrace();

}

}

}

  1. q行。控制台打印输出

2007-8-16 10:25:52 org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry crea

teTypeCreator

信息: Couldn’t find Java 5 module on classpath. Annotation mappings will not be su

pported.

userId=123, userName=试用户, lastLogin=Thu Aug 16 10:25:53 CST 2007


扩展主题

利用MTOM传输二进制对象(文gQ?/h2>

MTOM是XFire的一个组Ӟ可以协助利用压羃{手D|快的在网l上传输base64的SOAP对象

MTOM以及aegis默认支持如下几种java对象的数?/p>

  • byte[]
  • javax.activation.DataHandler
  • javax.activation.DataSource
  1. 配置启用MTOM

在Spring配置文g中需要MTOM的服务中加入如下配置

 <bean id=“userService” parent=“baseWebService”>

<property name=“serviceBean” ref=“userWS” />

<property name=“serviceClass”

value=“org.ave7.xfire.ws.UserService” />

<property name=”properties”>

<map>

<entry key=”mtom-enabled” value=”true” />

</map>

</property>

</bean>

  1. 在客L~写传输E序
 Service serviceModel = new ObjectServiceFactory()

.create(UserService.
class);

UserService service 
= (UserService) new XFireProxyFactory().create(

serviceModel,

“http:
//localhost:8080/XFireService/service/UserService”);

Client client 
= Client.getInstance(service);

client.setProperty(“mtom
-enabled”, “true”);

client.setProperty(HttpTransport.CHUNKING_ENABLED, “
true”);

User user 
= service.queryUserByAccoutId(“123″);

System.out

.println(“userId
=” + user.getUserId() + “, userName=

+ user.getUserName() + “, lastLogin=

+ user.getLastLogin());

ByteArrayDataSource byteData 
= new ByteArrayDataSource(

“Test Sending Byte”.getBytes(), “text
/plain; charset=UTF-8″);

service.transferDataSource(byteData);

附录

XFire在WebLogic 8.1中的配置

  1. Add the QName JAR file (qname.jar) into the WEB-INF/lib folder in your WAR file
  2. Add a file weblogic.xml into the WEB-INF folder in your WAR file
<!DOCTYPE weblogic-web-app PUBLIC

“-//BEA Systems, Inc.//DTD Web Application 8.1//EN”

“http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd”
>

<weblogic-web-app>

<container-descriptor>

<prefer-web-inf-classes>true</prefer-web-inf-classes>

</container-descriptor>

</weblogic-web-app>

QName JAR file (qname.jar) http://docs.codehaus.org/download/attachments/27836/qname.jar?version=1

参?/h1>

XFire On WebLogic 8.1
http://docs.codehaus.org/display/XFIRE/XFire+on+WebLogic+8.1



HIMMEL 2007-08-16 13:15 发表评论
]]>JSF Suckshttp://www.aygfsteel.com/lazing/archive/2007/07/31/133594.htmlHIMMELHIMMELTue, 31 Jul 2007 08:10:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/07/31/133594.htmlhttp://www.aygfsteel.com/lazing/comments/133594.htmlhttp://www.aygfsteel.com/lazing/archive/2007/07/31/133594.html#Feedback2http://www.aygfsteel.com/lazing/comments/commentRss/133594.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/133594.html
我不明白Q服务器端的E序p大么?
Z么都跑来对JavaScript动一堆手脚?br>
有h说的好,JSF是ASP.net in JAVA?br>N把前台后台؜Z谈,提供些预定义的控件就是良好的框架么?






HIMMEL 2007-07-31 16:10 发表评论
]]>
IE BLOG 公布免费的Develop Tool barhttp://www.aygfsteel.com/lazing/archive/2007/05/18/118382.htmlHIMMELHIMMELFri, 18 May 2007 07:29:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/18/118382.htmlhttp://www.aygfsteel.com/lazing/comments/118382.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/18/118382.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118382.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118382.htmlhttp://blogs.msdn.com/ie/archive/2005/09/16/469686.aspx

一些功能列表:
  • explore the DOM tree and find elements on the page
  • disable IE settings, view information
  • outline elements,
  • control images
  • resize pages to common screen resolutions
  • validate against existing standards and provides pointers to W3C specs
下蝲地址
http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en



HIMMEL 2007-05-18 15:29 发表评论
]]>
Ageci Notes: Authenticationhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118190.htmlHIMMELHIMMELThu, 17 May 2007 14:52:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118190.htmlhttp://www.aygfsteel.com/lazing/comments/118190.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118190.html#Feedback2http://www.aygfsteel.com/lazing/comments/commentRss/118190.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118190.html阅读全文

HIMMEL 2007-05-17 22:52 发表评论
]]>
Java Notes: Data types and Operatorshttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.htmlHIMMELHIMMELThu, 17 May 2007 14:48:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.htmlhttp://www.aygfsteel.com/lazing/comments/118189.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118189.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118189.htmlComprehend

  • A variable holds a value, while an object reference variable points to the memory that holds the object.
  • The short-circuit logical operators && and || operate only on boolean operands. For example, the expression
    9&&7 will not compile. Understand the difference between short-circuit logical operators and bitwise
    operators.
  • If the first expression of a && operator is false, the second expression is not evaluated, and if the first
    expression of a || operator is true, the second expression is not evaluated.

Look Out

  • Be on guard for words that are only slightly different from the Java keywords, such as synchronize instead of synchronized, implement instead of implements, and protect instead of protected.
  • Whether an array stores primitive variables or object references, the array itself is always an object.
  • It is illegal to include the array size in the array declaration.
  • Division by zero generates a runtime ArithmeticException only if the operands are integers. In case of float and double, the result of division by zero is infinity.
  • The result of the modulo operator always carries the sign of the first operand (i.e. the one before the operator);
    you can ignore the sign of the second operand.
  • You cannot instantiate an enum by using the new operator.

Memorize

  • Know the Java language keywords.
  • Know the range of values for all primitive data types.
  • All primitive data types except boolean and char are signed.
  • The first character of an identifier must be a letter, a dollar sign ($), or an underscore (_). Characters other than the first character in an identifier may be a letter, a dollar sign, an underscore, or a digit.


HIMMEL 2007-05-17 22:48 发表评论
]]>
Java Notes: Classes, Methods, and Interfacehttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.htmlHIMMELHIMMELThu, 17 May 2007 14:47:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.htmlhttp://www.aygfsteel.com/lazing/comments/118188.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118188.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118188.htmlComprehend
  • The method name and return type are mandatory in a method declaration. Even though you are not required to specify a modifier in a method declaration, the default modifier is assigned to the method, if you don’t declare one.
  • A static variable belongs to the class and not to a particular instance of the class, and therefore is initialized when the class is loaded, and before the class is instantiated.
  • Because a static method belongs to a class and not to a particular instance of the class, it cannot access the nonstatic methods and variables of the class in which it is defined.
  • An instance of an inner class can only exist in an instance of the outer class, and has direct access to all the instance variables and methods of the outer instance.
  • If you make a super call or a this call, it must be in the beginning of a constructor. That means you can make either a super call or a this call, but not both.

Look Out

  • The variable-length parameters list must appear last in the parentheses of a method and it consists of a data type, three dots, and a name, in that order.
  • A Java class cannot inherit from more than one class, but it can inherit from one class and one or more interfaces.
  • The class that inherits from an interface must provide implementation for all the methods that are declared in the interface if the class is not abstract.
  • An interface can extend another interface but it cannot implement another interface or a class.

Memorize

  • If you do not provide any constructor for a class you write, the compiler provides the default constructor for that class. If you write at least one constructor for the class, the compiler provides no constructor.
  • If you don not make a this or a super call in the beginning of a constructor, the compiler places a super() call there.
  • You use the keyword extends to write a derived class that inherits from a parent class, and use the keyword implements to write a class that inherits from an interface.
  • The methods in an interface are inherently public and abstract, and the variables in the interface are inherently public, final, and static.


HIMMEL 2007-05-17 22:47 发表评论
]]>
Microsoft Software Basic Processhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118187.htmlHIMMELHIMMELThu, 17 May 2007 14:37:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118187.htmlhttp://www.aygfsteel.com/lazing/comments/118187.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118187.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118187.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118187.html
  1. Plan an agenda.
  2. Define key business drivers.
  3. Define key success facts.
  4. Work out persona.
  5. Work out Scenario.
  6. High level architecture
  7. High level design
  8. Development
  9. QA
  10. Deployment


HIMMEL 2007-05-17 22:37 发表评论
]]>
数值方法笔?http://www.aygfsteel.com/lazing/archive/2007/05/17/118185.htmlHIMMELHIMMELThu, 17 May 2007 14:34:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118185.htmlhttp://www.aygfsteel.com/lazing/comments/118185.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118185.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118185.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118185.html关于q个W记

也许你已l学会了一门计机语言Q也怽会写一D不错的E序?

也许你在嘈杂的环境用不费力的可以用熟悉的IDE完成一个项目?

不过Q你q在? - * /?做所有的计算么?

q个W记是Z写出更加正确的程序,小的一个学习过E?

我不ȝ复杂的道理,只记录用得上的方案?

出现的一切代码都使用Java语言?

正确的计过E导致错误的计算l果

关于基本数D中的一些陷?

点数和实数

当早期的Fortran和algol创造出realq个关键字时Q你q真以ؓ那么是实敎ͼ不过说真的,你被骗了?

所以到了CQ我们拥有了float?

那么他们到底有什么不同呢Q?

单地?

System.out.println(”Value of 1/3: ” + (1/3f))

输?

Value of 1/3: 0.33333334

很简单,q是很早之前您就知道的四舍五入。当时我们只是那无法写完的@环在U怸划下一?#8221;?#8221;Q然后非常开心可以少写几个字W。如果你有一个负责Q的数学老师Q他Q她Q就会反复的叮咛你,要小心,计算时候要保留l果_ֺ往后一位的数倹{?

当这一切轮C计算机,我们叫它Q?

舍入误差

舍入误差有时相当惊h。对1/3q加840ơ,你会得到279.9915Q本应当?80Q,如何惊hQ我们会在下面看到?

不过有意思的事情Q和时候的情Ş不一P舍入误差q不是由于不能除或者是无理数造成的,cM?/5的数字连加之后也有误差。这是因为绝大多? 计算机是Z2q制体系的,所以IBM有用于商业计的10q制计算机。简单的事实是利用float表达?的幂ơ,在精度范围是没有舍入误差的?

l出常用定义Q?

作如下计,你会期待怎样的结果呢Q?

别偷懒,用你久远的口能力,很容易就可以得出Q它本来应该?。而事实上Q我们伟大的计算机的{案?222784.0

Z么?

因ؓQ?0000001/20000000的时候,{案本应该是0.50000005Q由于舍入误差,我们得到?.5000006?

接下来我们减?.5的时候,得到的应当是0.00000006Q这P我们׃׃所有的正确的数?

更糟p的是,计算Z实际得到的值是5.9604645e-8?

因此Q您的存ƾ户头上可能会^白无故减?222784元。只因ؓ银行军_向你支付利息之后Q调整了汇率?

呃,q一ơ,我们叫它Q?

相消误差——两个非常相q的值相减时Q如果消Ml大多数有效数|那么׃发生相消误差?br>舍入误差——是_值和其可表达g间的差倹{?

如果q有什么要说的Q那是Q?br>

Double比float 更接q实敎ͼ貌似不需要我说?br>点q算不遵守代数定?

比如Qa = 1.0, b = 3.0e-8, c = 4.0e-8

那么Q?nbsp;   (a+b)+c = 1.0

    a+(b+c) = 1.0000001

不过加法和乘法还是满交换律的?

下一ơ:轮到了整数?



HIMMEL 2007-05-17 22:34 发表评论
]]>
JavaMail API 实例汇?/title><link>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html</link><dc:creator>HIMMEL</dc:creator><author>HIMMEL</author><pubDate>Thu, 17 May 2007 14:30:00 GMT</pubDate><guid>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html</guid><wfw:comment>http://www.aygfsteel.com/lazing/comments/118184.html</wfw:comment><comments>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lazing/comments/commentRss/118184.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lazing/services/trackbacks/118184.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class="postentry"> <p>呃,好吧Q我只写q三个JavaMail的程序?/p> <p>都是扚w邮g守护E序。决定ȝ一下,希望非常q运扑ֈq篇文章的h不会再对q个困惑?/p> <h3>必须明白的基知识</h3> <ol> <li>STMP协议是如何工作的<br> 协议的标准在q里 <a >http://www.ietf.org/rfc/rfc2821.txt?number=2821</a><br> 下面是扼要说明(<a >http://www.freesoft.org/CIE/Topics/94.htm</a> Q: <blockquote> <p>Simple Mail Transfer Protocol (SMTP), documented in RFC 821, is Internet’s standard host-to-host mail transport protocol and traditionally operates over TCP, port 25. In other words, a UNIX user can type telnet hostname 25 and connect with an SMTP server, if one is present.</p> <p>SMTP uses a style of asymmetric request-response protocol popular in the early 1980s, and still seen occasionally, most often in mail protocols. The protocol is designed to be equally useful to either a computer or a human, though not too forgiving of the human. From the server’s viewpoint, a clear set of commands is provided and well-documented in the RFC. For the human, all the commands are clearly terminated by newlines and a HELP command lists all of them. From the sender’s viewpoint, the command replies always take the form of text lines, each starting with a three-digit code identifying the result of the operation, a continuation character to indicate another lines following, and then arbitrary text information designed to be informative to a human.</p> </blockquote> <p>事实上,你可以像使用DOS命o一样发送电子邮件?a >http://bbs.stcore.com/archiver/tid-8024.htm </a>当然因ؓ各种原因Q你的尝试不可能成功。事实上SMTP工作的时候就是简单的发送命令。取得认证,发送数据。得到反馈。确认退么简单? </p> </li> <li>SMTP中用于发送的数据<br> SMTP中发送的数据Q遵?font size="-1"><strong>Multipurpose Internet Mail</strong> <strong>Extensions</strong> (<strong>MIME</strong>)标准Q呃Q我不得不说Q这是这个星球上最重要的标准之一。所有的互联|通信基本都是Zq个标准的演化。除了电子邮Ӟ常见的应用还包括HTTP报文{(也就是所有网了Q,另外即?0q后发展的XMLQ其2q制数据发送仍然实用的MIME中的~码方式?br> 恩,q里涉及到邮g附g如何处理的问题。恩Q简单地说就是BASE64~码</font></li> </ol> <blockquote> <pre>Table 1: The Base64 Alphabet<br><br>Value Encoding Value Encoding Value Encoding Value Encoding</pre> <pre>0 A 17 R 34 i 51 z<br><br>1 B 18 S 35 j 52 0<br><br>2 C 19 T 36 k 53 1<br><br>3 D 20 U 37 l 54 2<br><br>4 E 21 V 38 m 55 3<br><br>5 F 22 W 39 n 56 4<br><br>6 G 23 X 40 o 57 5<br><br>7 H 24 Y 41 p 58 6<br><br>8 I 25 Z 42 q 59 7<br><br>9 J 26 a 43 r 60 8<br><br>10 K 27 b 44 s 61 9<br><br>11 L 28 c 45 t 62 +<br><br>12 M 29 d 46 u 63 /<br><br>13 N 30 e 47 v<br><br>14 O 31 f 48 w (pad) =<br><br>15 P 32 g 49 x<br><br>16 Q 33 h 50 y</pre> </blockquote> <p>在这U编码中Q我们将字符或者二q制~码?个比特位Zl,替换成相应的字符形式。比?/p> <pre>100110111010001011101001</pre> <p>转换l果是</p> <pre>100110 -> 38</pre> <pre>111010 -> 58<br><br>001011 -> 11<br><br>101001 -> 41</pre> <pre>38 -> m<br><br>58 -> 6<br><br>11 -> L<br><br>41 -> p</pre> <pre>m6Lp</pre> <p>于是Q我们就可以以文本的方式~码二进制流以及扩展ASCII字符Q比如中文字W?/p> <p>基础知识完毕Q下面是FAQ</p> <h3>Java发送电子邮仉要哪些Y件包</h3> <p>mail.jar 通常q会需?activation.jar</p> <blockquote> <p>下蝲地址<br> http://java.sun.com/products/javabeans/jaf/downloads/index.html<br> https://maven-repository.dev.java.net/nonav/repository/javax.mail/</p> </blockquote> <h3>如何发送邮?/h3> <p>关于Q?/p> <ul> <li>如何发送邮?/li> <li>如何发送带有附件的邮g</li> <li>如何发送中文邮?/li> <li>邮g中文标题q怎么?/li> <li>邮g附gq怎么办等{问?/li> </ul> <p>h看以下代?/p> <pre class="java"> <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">static</span> <span style="color: blue; font-weight: bold;">synchronized</span> <span style="color: #993333;">void</span> sendMail<span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">Properties</span></a> settings<span style="color: #66cc66;">)</span><br> <br> <span style="color: blue; font-weight: bold;">throws</span> <a ><span style="color: red; font-weight: bold;">Exception</span></a> <span style="color: #66cc66;">{</span><br> <br> <a ><span style="color: red; font-weight: bold;">Properties</span></a> props = <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">Properties</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.host"</span>, settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">MAIL_SERVER</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.user"</span>, settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_NAME</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.auth"</span>, <span style="color: #ff0000;">"true"</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//SMTP服务器用户验?/span><br> <br> <a ><span style="color: red; font-weight: bold;">Authenticator</span></a> auth = <span style="color: blue; font-weight: bold;">new</span> SMTPAuthenticator<span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_NAME</span><span style="color: #66cc66;">)</span>, <span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">PASSWORD</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> Session session = Session.<span style="color: #006600;">getDefaultInstance</span><span style="color: #66cc66;">(</span>props, auth<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #ff0000;">"true"</span>.<span style="color: #006600;">compareToIgnoreCase</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"DEBUG"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> session.<span style="color: #006600;">setDebug</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #66cc66;">}</span><br> <br><span style="color: #808080; font-style: italic;">//创徏消息?/span><br> <br> MimeMessage msg = <span style="color: blue; font-weight: bold;">new</span> MimeMessage<span style="color: #66cc66;">(</span>session<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄发送h邮g</span><br> <br> msg.<span style="color: #006600;">setFrom</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_MAIL</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄接收人邮?/span><br> <br> address = <span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> <span style="color: #66cc66;">{</span> <span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">(</span>rs<br> <br> .<span style="color: #006600;">getString</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"GRE_mail"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">}</span>;<br> <br> msg.<span style="color: #006600;">setRecipients</span><span style="color: #66cc66;">(</span>Message.<span style="color: #006600;">RecipientType</span>.<span style="color: #006600;">TO</span>, address<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄主题Q中文编?/span><br> <br> msg.<span style="color: #006600;">setSubject</span><span style="color: #66cc66;">(</span>subject, <span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span>;<br> <br> msg.<span style="color: #006600;">setSentDate</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">Date</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br><a ><span style="color: red; font-weight: bold;">String</span></a> content = <span style="color: #ff0000;">"邮g正文"</span>;<br> <br> MimeBodyPart mbp1 = <span style="color: blue; font-weight: bold;">new</span> MimeBodyPart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> mbp1.<span style="color: #006600;">setText</span><span style="color: #66cc66;">(</span>content, <span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//邮g附g</span><br> <br>MimeBodyPart attachFilePart = <span style="color: blue; font-weight: bold;">new</span> MimeBodyPart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br><a ><span style="color: red; font-weight: bold;">File</span></a> file = <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">File</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"中文附g.txt"</span><span style="color: #66cc66;">)</span>;<br> <br>FileDataSource fds = <span style="color: blue; font-weight: bold;">new</span> FileDataSource<span style="color: #66cc66;">(</span>file.<span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br>attachFilePart.<span style="color: #006600;">setDataHandler</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> DataHandler<span style="color: #66cc66;">(</span>fds<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> sun.<span style="color: #006600;">misc</span>.<span style="color: #006600;">BASE64Encoder</span> enc = <span style="color: blue; font-weight: bold;">new</span> sun.<span style="color: #006600;">misc</span>.<span style="color: #006600;">BASE64Encoder</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #808080; font-style: italic;">//解决中文附g名称</span><br> <br> attachFilePart.<span style="color: #006600;">setFileName</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"=?gbk?B?"</span><br> <br> + enc.<span style="color: #006600;">encode</span><span style="color: #66cc66;">(</span>file.<span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>.<span style="color: #006600;">getBytes</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> + <span style="color: #ff0000;">"?="</span><span style="color: #66cc66;">)</span>;<br> <br>Multipart mp = <span style="color: blue; font-weight: bold;">new</span> MimeMultipart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> mp.<span style="color: #006600;">addBodyPart</span><span style="color: #66cc66;">(</span>mbp1<span style="color: #66cc66;">)</span>;<br> <br> mp.<span style="color: #006600;">addBodyPart</span><span style="color: #66cc66;">(</span>attachFilePart<span style="color: #66cc66;">)</span>;<br> <br>msg.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">(</span>mp<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">// send the message</span><br> <br> msg.<span style="color: #006600;">saveChanges</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> Transport.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span>msg<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #66cc66;">}</span></pre> <p>q是上面用户验证用到的类</p> <pre class="java"><span style="color: blue; font-weight: bold;">class</span> SMTPAuthenticator <span style="color: blue; font-weight: bold;">extends</span> javax.<span style="color: #006600;">mail</span>.<a ><span style="color: red; font-weight: bold;">Authenticator</span></a> <span style="color: #66cc66;">{</span></pre> <pre class="java"> <span style="color: blue; font-weight: bold;">private</span> <a ><span style="color: red; font-weight: bold;">String</span></a> username;<br> <br> <span style="color: blue; font-weight: bold;">private</span> <a ><span style="color: red; font-weight: bold;">String</span></a> password;<br> <br> <span style="color: #808080; font-style: italic;">/**<br> <br> * @param username<br> <br> * @param password<br> <br> */</span><br> <br> <span style="color: blue; font-weight: bold;">public</span> SMTPAuthenticator<span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a> username, <a ><span style="color: red; font-weight: bold;">String</span></a> password<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> <span style="color: blue; font-weight: bold;">this</span>.<span style="color: #006600;">username</span> = username;<br> <br> <span style="color: blue; font-weight: bold;">this</span>.<span style="color: #006600;">password</span> = password;<br> <br> <span style="color: #66cc66;">}</span><br> <br> <span style="color: blue; font-weight: bold;">public</span> <a ><span style="color: red; font-weight: bold;">PasswordAuthentication</span></a> getPasswordAuthentication<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> <span style="color: blue; font-weight: bold;">return</span> <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">PasswordAuthentication</span></a><span style="color: #66cc66;">(</span>username, password<span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #66cc66;">}</span><br> <br><span style="color: #66cc66;">}</span></pre> <h3>邮g发送出?/h3> <blockquote> <p>What causes an “javax.activation.UnsupportedDataTypeException: no object DCH for MIME type xxx/xxxx javax.mail.MessagingException: IOException while sending message;” to be sent and how do I fix this? [This happens for known MIME types like text/htm</p> </blockquote> <p>事实上这个是邮g发送时验证lg讄不当引v的,q个lg配置Ҏ如下</p> <blockquote> <p>(http://java.sun.com/j2ee/1.4/docs/api/javax/activation/MailcapCommandMap.html)</p> <p>The MailcapCommandMap looks in various places in the user’s system for mailcap file entries. When requests are made to search for commands in the MailcapCommandMap, it searches mailcap files in the following order:</p> <p>1) Programatically added entries to the MailcapCommandMap instance.<br> 2) The file .mailcap in the user’s home directory.<br> 3) The file /lib/mailcap.<br> 4) The file or resources named META-INF/mailcap.<br> 5) The file or resource named META-INF/mailcap.default (usually found only in the activation.jar file).</p> </blockquote> <p>我选用了第四种ҎQ在生成的Jar文g中加入了 META-INF/mailcap.</p> <pre class="apache"><span style="color: #adadad; font-style: italic;">#</span><br><span style="color: #adadad; font-style: italic;"># This is a very simple 'mailcap' file</span><br><span style="color: #adadad; font-style: italic;">#</span><br>image/gif;; x-java-view=com.sun.activation.viewers.ImageViewer<br>image/jpeg;; x-java-view=com.sun.activation.viewers.ImageViewer<br>text/*;; x-java-view=com.sun.activation.viewers.TextViewer<br>text/*;; x-java-edit=com.sun.activation.viewers.TextEditor<br>text/html;; x-java-content-handler=com.sun.mail.handlers.text_html<br>text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml<br>text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain<br>multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed<br>message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822</pre> </div><img src ="http://www.aygfsteel.com/lazing/aggbug/118184.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lazing/" target="_blank">HIMMEL</a> 2007-05-17 22:30 <a href="http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ave7.net BLSNS框架研究报告http://www.aygfsteel.com/lazing/archive/2007/01/19/94993.htmlHIMMELHIMMELFri, 19 Jan 2007 14:34:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/01/19/94993.htmlhttp://www.aygfsteel.com/lazing/comments/94993.htmlhttp://www.aygfsteel.com/lazing/archive/2007/01/19/94993.html#Feedback4http://www.aygfsteel.com/lazing/comments/commentRss/94993.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/94993.html呼呼Q写q个别h看不懂的题目很不着调。其实核心内容就是对Java AJAX框架做个笔讎ͼ记录一下我的实践心得?

因ؓ要还换空间了Q终于可以ؓ自己的网站写JavaE序了,刚好老师要我ȝ一下,提供一个即插即用的Ajax JAVA环境?

汗~~不过单美Q我开心的说一下吧?

框架选择汇?

选择理由

Dojo

我最q是Dojo。Dojo提供了丰富的Widget和不断增加的教程文。拥有了IBM和SUN的官Ҏ持。更重要的是QDojo不止为Java设计QDojo是一个通用的^収ͼq意味着Q所有最新的技术都可以UL到Dojo上面来,而你q不需要重新学习?

Dojo最大的q是,启动~慢Q官方网站在|络质量不好的时候会有死机的感觉。不q依然记?.3?.4的巨大惊喜。我怿随着Dojo的成熟,对其的学习是一U保值的投资?

DWR

q是目前几个框架中,我唯一没有在实际项目中使用q的。之前用Dojo和WW写程序的时候,使用JSON作ؓ数据 媒介Q没有用RPCQ。写了很多代码来负责同步JSON与JAVA对象。目前看来DWR可以很好的解册个问题。而且Q随着Annotation的流行,q配|都不用了?

Struts2 / WW

目前没有用过Struts 2不过从前wWW的表现来看,l对是开发速度之选。丰富的扩展支持Q良好的接口设计Qؓ易变的Web环境提供了舒适的开发体验。再加上Apache的大名,那就素质量的保证啊。虽然有Ajax支持的鸡肋(T_T原谅我,我是真的不会用那个)。Struts2同样开始支持Annotation配置Q真是ؓ我省心啊?

Spring

Spring is coming?.

没有理由Q只要不用EJBQ那么只有Spring才是J2EE的选择Q良好的扩展性,无所不在的简z。M记怎么说来着Q和谐美啊。Spring是和谐Q让那一片一片菱角分明的框架l合的天衣无~。总而言之一句话QSpring是端午节的p米啊。(那谁是粽子叶呢?Q?

Hibernate ?iBatis

其实持久层的选择p省重一点了?

Hibernate很方便,方便到太Ҏ犯错误。所以我把iBatis列进去,q是性能和健壮性的考虑?

我明白Hibernate有多么方便,如果两三个月p交付一个项目,Hibernate能够让你忘掉SQL的存在。但是要做一个逻辑复杂的SNS站点QiBatis无疑更轻巧更考验才智?

以上Q再加上Acegi和axis2Q暂时没打算用)Q开心的玩Java AJAX?/p>

HIMMEL 2007-01-19 22:34 发表评论
]]>
վ֩ģ壺 | | | ˮ| ˮ| | | կ| | | | ʱ| | | | | | | | | | կ| | | ˫| | | | | | ٺ| ͩ| ۶| | | ҳ| ¡| | ԭ| | ؿ˹|