Advertisement
Guest User

lolololololololololol

a guest
Oct 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package fr.info.sdweb;
  2.  
  3. import java.io.IOException;
  4. import java.util.Hashtable;
  5.  
  6. import javax.naming.Context;
  7. import javax.naming.InitialContext;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.servlet.http.HttpSession;
  14.  
  15. import fr.info.ejb.HelloejbRemote;
  16. import fr.info.model.HelloBean;
  17.  
  18. /**
  19. * Servlet implementation class HelloEJBServlet
  20. */
  21. @WebServlet("/HelloEJBServlet")
  22. public class HelloEJBServlet extends HttpServlet {
  23. private static final long serialVersionUID = 1L;
  24.  
  25. /**
  26. * @see HttpServlet#HttpServlet()
  27. */
  28. public HelloEJBServlet() {
  29. super();
  30. // TODO Auto-generated constructor stub
  31. }
  32.  
  33. /**
  34. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  35. */
  36. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  37. // TODO Auto-generated method stub
  38. HttpSession session = request.getSession(true);
  39. String name = request.getParameter("nom");
  40. String message = "" ;
  41. //Connexion JNDI (annuaire pour localiser l'EJB)
  42. try {
  43. final Hashtable jndiProperties = new Hashtable();
  44. jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
  45. final Context context = new InitialContext(jndiProperties);
  46. final String appName = "HelloEAR";
  47. final String moduleName = "HelloEJBProject";
  48. //final String distinctName = "";
  49. //localier ejb sur jboss 7.2
  50. //sur jboss eap n'est plus nécessaire de spécifier distinct name
  51. final String beanName = "HelloEJB";
  52. final String viewClassName = HelloejbRemote.class.getName();
  53. //HelloEJBRemote remote = (HelloEJBRemote)
  54. //context.lookup("ejb:"+appName+"/"+moduleName+"/"+//"/"+distinctName+"/"+beanName+"!"+viewClassName);
  55.  
  56. HelloejbRemote remote = (HelloejbRemote)context.lookup("ejb:"+appName+"/"+moduleName+"/"+beanName+"!"+viewClassName);
  57. message = remote.direBonjour(name);
  58. }catch(Exception e) {
  59. e.printStackTrace();
  60. }
  61.  
  62. HelloBean bean = new HelloBean();
  63. bean.setName(message);
  64. session.setAttribute("beanHello", bean);
  65. response.sendRedirect("HelloEJB.jsp");
  66. }
  67.  
  68. /**
  69. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  70. */
  71. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  72. // TODO Auto-generated method stub
  73. doGet(request, response);
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement