标签:int utf-8 interface doc software javabean header 配置文件 项目
EJB是sun的JavaEE服务器端组件模型,设计目标与核心应用是部署分布式应用程序。简单来说就是把已经编写好的程序(即:类)打包放在服务器上执行。凭借java跨平台的优势,用EJB技术部署的分布式系统可以不限于特定的平台。EJB (Enterprise JavaBean)是J2EE(javaEE)的一部分,定义了一个用于开发基于组件的企业多重应用程序的标准。其特点包括网络服务支持和核心开发工具(SDK)。 在J2EE里,Enterprise Java Beans(EJB)称为Java 企业Bean,是Java的核心代码,分别是会话Bean(Session Bean),实体Bean(Entity Bean)和消息驱动Bean(MessageDriven Bean)
Dubbo是一个分布式的服务架构,可直接用于生产环境作为SOA服务框架。(必须依赖于Spring框架,必须启动Zookeeper服务,用于注册接口),与EJB一样,都可以实现接口与实现类的远程类调用,实现接口,可以将核心业务抽取出来,作为独立的服务,使前端应用能更快速和稳定的响应。
@Local public interface Iejb { String sayHelloWord(String userName); }
@Stateless @Local public class EjbBean implements Iejb { @Override public String sayHelloWord(String userName) { return userName+":HelloWord!"; } }
@Stateless public class HelloWorldLocalController extends HttpServlet { @EJB private Iejb iejb; @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = response.getWriter(); String s = JSON.toJSONString(helloWorld.sayHello("wangping")); pw.write(s); pw.close(); } }
@Local public interface Iejb2 { String sayHelloWord(String userName); }
@Stateless @Alternative public class IejbBean implements Iejb2 { @Override public String sayHello(String userName) { return userName+":Hello"; } }
@Stateless @Alternative public class NewIejbBean implements Iejb2 { @Override public String sayHello(String userName) { return userName+":HelloWorld"; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee"> <alternatives> <class>com.phhc.ejb_eg2.NewIejbBean</class> </alternatives> </beans>
public class DemoServlet2 extends HttpServlet { @Inject private Iejb2 iejb; @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) { try { response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = response.getWriter(); String s = JSON.toJSONString(iejb.sayHello("wangping")); pw.write(s); pw.close(); }catch (Exception e){ e.printStackTrace(); } } }
@Remote public interface HelloWordRemote extends Serializable { Model sayHello(String world); }
@Stateless(name = "HelloWorldBeanEJB") @Remote(HelloWordRemote.class) @Local(HelloWordLocal.class) public class HelloWorldBean implements HelloWordRemote,HelloWordLocal { @Override public String sayHello(String world) { return "HelloWorld:"+world; } }
<?xml version="1.0" encoding="UTF-8" ?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> <enterprise-beans> <session> <ejb-name>HelloWorldBeanEJB</ejb-name> <remote>com.phhc.ejb.servcices.HelloWordRemote</remote> <local>com.phhc.ejb.servcices.HelloWordLocal</local> <ejb-class>com.phhc.ejb.servcices.impl.HelloWorldBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar>
public class HelloWordController extends HttpServlet { @EJB(name = "ejb/HelloWorldBeanEJB") private HelloWordRemote helloWord;
@Remote public interface HelloWordRemote extends Serializable { Model sayHello(String world); }
@Stateless(name = "HelloWorldBeanEJB") public class HelloWorldBean implements HelloWordRemote { public HelloWorldBean() { } @Override public Model sayHello(String world) { Model model = new Model(); model.setName(world); model.setSex("男"); model.setHobby("女"); return model; } }
<?xml version="1.0" encoding="UTF-8" ?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> <enterprise-beans> <session> <ejb-name>HelloWorldBeanEJB</ejb-name> <remote>com.phhc.ejb.servcices.HelloWordRemote</remote> <ejb-class>com.phhc.ejb.servcices.impl.HelloWorldBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar>
public class HelloWordController extends HttpServlet { @EJB(name = "ejb/HelloWorldBeanEJB") private HelloWordRemote helloWord; @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = response.getWriter(); String s = JSON.toJSONString(helloWord.sayHello("wanping")); pw.write(s); pw.close(); } }
?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sun-web-app PUBLIC ‘-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN‘ ‘http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_3-0.dtd‘> <sun-web-app> <ejb-ref> <ejb-ref-name>com.phhc.controller.HelloWordController/helloWorld</ejb-ref-name> </ejb-ref> <jsp-config/> </sun-web-app>
标签:int utf-8 interface doc software javabean header 配置文件 项目
原文地址:http://www.cnblogs.com/javawan/p/6636098.html