jboss as7 访问ejb通用类
来源:互联网 发布:php怎么接私活 编辑:程序博客网 时间:2024/06/05 01:12
package com.synnex.ejb.util;import java.util.Properties;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;public class EjbUtil {private static Context initialContext;private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";private static Context getInitialContext() throws NamingException{if(initialContext == null){Properties prop = new Properties();prop.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);initialContext = new InitialContext(prop);}return initialContext;}public static Object lookup(String jndi) throws Exception{return getInitialContext().lookup(jndi);}private static Object lookup(Class<?> serviceClass, String moduleName, String beanName) throws Exception { final String appName = "";//ear包的名字,如果没有ear包,那么这个就是空字符串就行 final String distinctName = ""; final String interfaceName = serviceClass.getName(); String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + interfaceName; System.out.println("JNDI: " + jndi);return getInitialContext().lookup(jndi); }public static Object lookupRemoteBizService(Class<?> serviceClass, String moduleName) throws Exception{String beanName = serviceClass.getSimpleName().replace("Remote", "");return lookup(serviceClass, moduleName, beanName);}}
调用DEMO
package com.synnex.servlet;import java.io.IOException;import java.io.OutputStream;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.hua.ejb.LoginBeanRemote;import com.synnex.ejb.util.EjbUtil;/** * Servlet implementation class TestRemoteEJB */@WebServlet("/TestRemoteEJB")public class TestRemoteEJB extends HttpServlet {private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public TestRemoteEJB() { super(); // TODO Auto-generated constructor stub }/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doPost(request, response);}/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setHeader("Content-type", "text/html;charset=UTF-8"); //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859 response.setCharacterEncoding("UTF-8"); try {LoginBeanRemote loginBean = (LoginBeanRemote)EjbUtil.lookupRemoteBizService(LoginBeanRemote.class, "MyEJBServer");String str = loginBean.login("ejb", "123456");String str1 = loginBean.login("ejb", "qwerty");request.setCharacterEncoding("utf-8");System.out.println(str);System.out.println(str1);OutputStream ps = response.getOutputStream(); //这句话的意思,使得放入流的数据是utf8格式 ps.write(str.getBytes("UTF-8")); ps.write("<br>".getBytes("UTF-8")); ps.write(str1.getBytes("UTF-8")); //response.getWriter().write(str);//response.getWriter().write("<br>");//response.getWriter().write(str1);response.getWriter().flush();} catch (Exception e) {e.printStackTrace();}}}
以上代码来自网络
0 0
- jboss as7 访问ejb通用类
- jboss as7.1 https访问
- JBoss远程访问EJB
- JBoss AS7 用户指南
- JBoss AS7 用户指南
- [通译]JBoss AS7 用户指南
- jboss as7 JBAS015052
- ubuntu14.04+JBoss AS7
- Jboss As7 设定字符集
- JBoss AS7 快速配置
- jboss-as7 install dcm4chee
- JBoss as7下执行JDNI
- jboss-AS7配置postgrsql笔记
- jboss as7 调整jvm内存
- [JBOSS] jboss AS7 如何监听所有地址 .
- 在JBoss AS7中配置PostgreSQL数据源
- 在JBoss AS7中进展项目部署
- Using Encrypted DataSource Password in JBoss AS7
- 多线程
- 黑马程序员Android 增强版百分比布局库 为了适配而扩展
- Android开发编码规范导致的内存泄露问题
- 采用广播接收者拦截外拨电话及其特性
- android缓存数据到本地放在哪儿最好?
- jboss as7 访问ejb通用类
- bzoj-1123 BLO
- 如何快速掌握一门新技术/语言/框架
- 关于奇怪的并行进程分析
- Android_开启应用
- 黑马程序员Volley 图片加载相关源码解析
- 用html中img元素画横竖直线的方法
- Ubuntu安装谷歌中文输入法
- Struts 2 mapping interceptors to action