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
先谢谢大家了。
{
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
先谢谢大家了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货