struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shafiqul Islam" <>
Subject Session LOST between Request processor and Action
Date Thu, 06 Apr 2006 13:06:06 GMT

It seems that I am loosing the session information between the Request
processor and Action.  Any idea to what I may be doing wrong?  Thanks.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 1.2//EN"
  <forward name="welcome" path="/" redirect="false" />
      <forward name="Success" path="/jsp/welcome.jsp" />      
 <controller inputForward="false"
 <message-resources parameter="mysiteResources" null="false"/>

package com.mysite;

import java.util.*;
import javax.servlet.*;
import org.apache.log4j.Logger;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.config.ForwardConfig;

public class MyRequestProcessor extends RequestProcessor {

  protected boolean processPreprocess(HttpServletRequest request,
                                      HttpServletResponse response) {

    Logger log = Logger.getLogger(this.getClass().getName());
    HttpSession session = request.getSession(true);

    String username = (String)session.getAttribute("userName");
    if (null == username) {"Creating new Guest username");
      session.setAttribute("userName", "Guest");
    return true;

package com.mysite.action;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.apache.log4j.Logger;
import com.mysite.bean.WelcomeBean;

public class WelcomeAction  {

  public WelcomeAction() {}

  public ActionForward executeAction(ActionMapping mapping,
                                       ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
throws Exception {

    Logger log = Logger.getLogger(this.getClass().getName());    
    HttpSession session = request.getSession(false);
    ActionForward actionforward = null;
    String defaultUser = (String)session.getAttribute("userName");
    WelcomeBean wBean = new WelcomeBean();
    wBean.setGreeting("Hello There");
    wBean.setUsername(defaultUser); // Why am I getting null???

    request.setAttribute("WelcomeBean", wBean);"defaultUser: " + defaultUser); // this is null

    return actionforward = mapping.findForward("Success");

Shafiq Islam | Web Application Developer | VERTIS
2500 Metro Blvd. | St. Louis, MO  63043 | P 314.432.8800 | F
314.692.0309 |

Vertis is the premier provider of targeted advertising, media, and
marketing services that drive consumers to marketers more effectively.

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