EJB 3.0 怎么返回 StringBuffer?StringBuffer为什么为空啊?
class Test
{
void change(StringBuffer a)
{
a.append( "hehe ");
}
public static void main(String[] args)
{
StringBuffer b=new StringBuffer( "haha ");
Test t= new Test();
t.change(b);
System.out.println(b);
}
}
运行后,打印 hahahehe
但是在EJB 3.0 中
//RoleControl.java
-----------------------
package com.shitong.authority;
public interface RoleControl
{
boolean QueryDefaultRole(StringBuffer xmlstring);
}
------------------------
//RoleControlBean.java
-----------------------
package com.shitong.authority.imp;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import java.util.*;
import com.shitong.authority.*;
import java.io.*;
@Stateless
@Remote ({RoleControl.class})
@Local ({RoleControl.class})
public class RoleControlBean implements RoleControl
{
public boolean QueryDefaultRole(StringBuffer xmlstring)
{
xmlstring.append( "hehe ");
return true;
}
}
-----------------------
//RoleControlBeanClient
-----------------------
package com.shitong.authority.imp;
import com.shitong.authority.*;
import java.util.Properties;
import javax.naming.InitialContext;
public class RoleControlBeanClient
{
public static void main(String[] args)
{
Properties props = new Properties();
props.setProperty( "java.naming.factory.initial ", "org.jnp.interfaces.NamingContextFactory ");
props.setProperty( "java.naming.provider.url ", "localhost:1099 ");
props.setProperty( "java.naming.factory.url.pkgs ", "org.jboss.naming ");
try
{
InitialContext ctx = new InitialContext(props);
RoleControl role = (RoleControl) ctx.lookup( "RoleControlBean/remote ");
StringBuffer sXmlString=new StringBuffer( "haha ");
role.QueryDefaultRole(sXmlString);
System.out.println(sXmlString);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
运行后,结果还是haha,不是hahahehe
先谢谢大家了。
[解决办法]
等高手解答。
顶
[解决办法]
EJB的调用采用值传递方式,所以它不会改变你原来的对象(sXmlString)的值
[解决办法]
你可以组织一下这个字符串,比如说按一些的规律去装好一个字符串,然后返回的时候解析这个字符串啊
[解决办法]
肯定要返回才行嘛,EJB多用于分布式应用,不是一个jvm不可能传引用
[解决办法]
唉,不是NO EJB了吗?怎么还有人用EJB啊