I have a problem with sessions. This is not a new problem it has been
something that has been bugging me since I started developing for GAE,
I am using SDK 1.3.3.1

Things I have done:
1. Enabled sessions in app-engine.xml with <sessions-enabled>true</
sessions-enabled>.
2. Implemented Serializable in the objects I would like to persist.
3. RTFM but there's only one paragraph and it doesn't give much away.

For example I am using flash messages to give feedback to the user:

if (email.send()) {
    flash = new FlashMessage(FlashMessage.SUCCESS, "Your message has
been sent");
    session.setAttribute(FlashMessage.SESSION_KEY, flash);
    response.sendRedirect(URL.HOME);
} else {
    flash = new FlashMessage(FlashMessage.ERROR,
FlashMessage.INVALID_FORM_DATA);
    session.setAttribute(FlashMessage.SESSION_KEY, flash);
 
getServletContext().getRequestDispatcher( 
CONTACT_FORM).forward(request,response);
}

When the request is forwarded to a JSP via
getRequestDispatcher.forward() the flash message displays like its
supposed to. When the request is redirected via
response.sendRedirect() nothing happens. The message is displayed via
the same JSP template in both scenarios as follows:

<%   if (session.getAttribute(FlashMessage.SESSION_KEY) != null) {
           FlashMessage flash =
(FlashMessage)session.getAttribute( FlashMessage.SESSION_KEY);
%>
<%= flash.display() %>
<% }    %>

The class FlashMessage is included below:

import java.io.Serializable;

/**
 * HTML element used to give feedback to client based on server side
operations.
 * The flash message will be displayed as a DIV of class type.
 */
public class FlashMessage implements Serializable {
        private static final long serialVersionUID = 8109520737272565760L;

        /** Session key, where the flash message is stored */
        public static final String SESSION_KEY = "flashMessage";

        /
****************************************************************************
Class Types */
        /** Negative feedback message type */
        public static final String ERROR = "error";
        /** Positive feedback message type */
        public static final String SUCCESS = "success";

        /
****************************************************************************
Messages */
        /** Invalid form data */
        public static final String INVALID_FORM_DATA = "Your request failed
to validate, please check the fields below.";

        private String message;
        private String type;

        /**
         * @param type Message type
         * @param message Message
         */
        public FlashMessage (String type, String message) {
                this.type = type;
                this.message = message;
        }

        /**
         * @return HTML string representing the DIV element of the flash
message.
         */
        public String display(){
                return "<div id='flash' class='" + this.type + "'>" + 
this.message +
"</div>";
        }
}


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to