You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Abe Weintraub <tr...@panix.com> on 2003/07/18 23:43:57 UTC

retaining HttpSession when using xtags

Hi,

I am working on an web app that is running under tomcat 4.1.17 and using
taglibs xtags, and was hoping to get some help for a problem we are
having.

The problem is that a new HttpSession is being created for each call to
the Servlet and we don't want it to be.  The problem seems to be in how
the xtags:style tag is communicating with the Servlet (not forwarding
the request?).

The Servlet creates a new Session every time the test.jsp contacts it
via the xtag.  This problem does not occur when accessing the servlet
directly without going through the test.jsp.

Is there any way to forward the request and session to the Servlet and
back to the JSP and still use the xtags:style?
  
We would rather not have to refactor the entire app, and we realize it
is lame to have the servlet manually create the XML as a String.


Thanks.
-Abe


Here is the JSP code that uses the xtags.

<!-- test.jsp -->
<%

String xsl = "xsl/test.xsl";
xml =
"http://localhost:8080/ourWebApp/servlet/Foo?method=getFoobar&someParam=99";

%>
<%=session.getId() %>

<xtags:style
    xml="<%= xml %>"
    xsl="<%= xsl %>" />

/*---------------------------------------------------------------------------------------*/

// foobarServlet.java
// Now here is the relevant Servlet code that creates a valid XML
response as a String

protected doPost (HttpServletRequest req , HttpServletResponse rsp) {

   HttpSession loSession   = req.getSession(true);
   loSession.setAttribute("listener", this);

   log.debug("Your session id is: " + loSession.getId());

   if(loSession.isNew()) {
      log.debug("new session");
   } else {
      log.debug("old session");
   }
   
   String lsXml = this.someStuffThatCreatesXML();

   try {
     PrintWriter out = rsp.getWriter() ;
     out.println(lsXml) ;

  } catch(IOException e) {
     log.error ("Error exporting XML: "+e+".") ;
  }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org