cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Beat De Martin <beat.demar...@gmx.ch>
Subject Re: xsp session
Date Tue, 04 Feb 2003 21:08:52 GMT
Hi Cyril
Why don't use an action, I think it's better not to have too much Java code
in your xsp-pages.
In an action you can take your code as it is.
Cheers
Beat

> Hi,
> 
> I would like to deal with session through xsp, and serve as far as
> possible
> the same goal as with the following servlet: e.g put all the parameters
> named 'item' in the object of type Vector 'items' bound to the current
> session, so that it would be possible to list at any time all of the items
> chosen so far by the client in his session.
> 
>  public void doGet(HttpServletRequest req, HttpServletResponse res)
>                                throws ServletException, IOException {
>     res.setContentType("text/html");
>     PrintWriter out = res.getWriter();
> 
>     // Get the current session object, create one if necessary.
>     HttpSession session = req.getSession(true);
> 
>     // Cart items are maintained in the session object.
>    Vector items = (Vector)session.getAttribute("cart.items");
>         if (items == null) { items = new Vector(10,5);}
> 
>       String item = req.getParameter("item");
>       items.add(item);
> 
>        session.setAttribute("cart.items",items);
> 
>     out.println("<HTML><HEAD><TITLE>SessionTracker
> modifie</TITLE></HEAD>");
>     out.println("<BODY><H1>Session Tracking Demo</H1>");
> 
>     // Print the current cart items.
>     out.println("You currently have the following items in your
> cart:<BR>");
>     if (items == null) {
>       out.println("<B>None</B>");
>     }
>     else {
>       out.println("<UL>");
>       for (int i = 0; i < items.size(); i++) {
>         out.println("<LI>" + items.get(i));
>       }
>       out.println("</UL>");
>     }
> 
> 
>     out.println("</BODY></HTML>");
>   }
> }
> 
>  Below is the xsp i've written for the moment,: this is working fine, but
> does not do what I want: because each time the client chooses an item and
> pass it via the parameter 'item', instead of being added in the object
> cart.items, its value overrides this of the preceding parameter.
> 
> <?xml version="1.0"?>
> 
> <xsp:page
> 
> xmlns:xsp="http://apache.org/xsp"
> 
> xmlns:xsp-session="http://apache.org/xsp/session/2.0"
> 
> xmlns:xsp-request="http://apache.org/xsp/request/2.0"
> 
> create-session="true">
> 
> <html>
> 
> <xsp-session:set-attribute name="cart.items"><xsp-request:get-parameter
> name="item"/></xsp-session:set-attribute>
> 
> <b>You currently have the following items in your cart:</b>
> <xsp-session:get-attribute name="cart.items"/>
> 
> <br/>
> 
> <b>Your session was created:</b> <xsp-session:get-creation-time
> as="string"/>
> 
> </html>
> 
> </xsp:page>
> 
> Some of you would know how I can improve my code? Indeed, I would like
> cart.items to be like a Vector, so that it would be possible to put merely
> values onto it.
> Thanks in advance for your help,
> Cyril.
> 
> 
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>
> 

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message