less than 1 minute read

for tomcat
add crossContext="true" to server.xml for the web applications context:
<Context docBase="C:/eclipse/workspace/WebAppA/WebContent"  
path="/WebAppA" crossContext="true" reloadable="true">

</Context>



<Context docBase="C:/eclipse/workspace/WebAppB/WebContent"
path="/WebAppB" crossContext="true" reloadable="true">

</Context>


set a variable in webappa:
ServletContext myContext =  session.getServletContext();

           
myContext.setAttribute("userid", userid);


forward to webappb get the value set in webappa:
     
ServletContext otherContext = session.getServletContext().getContext("/WebAppA");

   
String account = (String)otherContext.getAttribute("userid");

Tags:

Updated:

Comments