tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "martin\(Feng-Chang\)" <mar...@cht.com.tw>
Subject how two web applications share a java bean object ?
Date Thu, 17 Jul 2003 11:16:02 GMT
Dear All:

 I set a java bean in one web application, whether add this bean to session or ServletContext.
 I can't get it in the other web application.

 How does a bean transmit between different web applications in Tomcat ?

 Web Application 1
------------------------ servlet1 --------------------------------
    MyBean bean1 = new MyBean();
     bean1.setName("martin");
     bean1.setAge(25);

     ServletConfig config = getServletConfig();
     ServletContext sc = config.getServletContext();
     sc.setAttribute("UserInfo",bean1);
----------------------------------------------------------------------

Web Application 2
-----------------------  servlet2 ------------------------------------
     ServletContext sc = getServletContext();
     MyBean bean2 = (MyBean)sc.getAttribute("UserInfo");

     resp.setContentType("text/html; charset=Big5");
     PrintWriter out = resp.getWriter();
     out.println("<h2>this is Get servlet in </h2>");
     out.println(req.getRequestURI());
     out.println("Name : "+bean2.getName());
     out.println("Age : "+bean2.getAge());
     out.close();
---------------------------------------------------------------------
 servlet 2 show nothing ....

 Thank a lot.
 Best regards,                 
 
 Martin


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message