struts-user mailing list archives

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

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.

---Struts-config---
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 1.2//EN"
 
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
 <data-sources/>
 <form-beans/>
 <global-exceptions/>
 <global-forwards>
  <forward name="welcome" path="/welcome.do" redirect="false" />
 </global-forwards>
 <action-mappings>
 
   <action
      path="/welcome"
      type="com.mysite.action.WelcomeAction"
      scope="request"
      validate="false">
      <forward name="Success" path="/jsp/welcome.jsp" />      
   </action> 
   
 </action-mappings>
 
 <controller inputForward="false"
             contentType="text/html;charset=UTF-8"
             locale="true"
             nocache="true"
             processorClass="com.mysite.MyRequestProcessor"/>
    
 <message-resources parameter="mysiteResources" null="false"/>
 
</struts-config>

---RequestProcessor---
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) {
      log.info("Creating new Guest username");
      session.setAttribute("userName", "Guest");
    }
    return true;
  }
}

---Action---
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);

    log.info("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
sislam@vertisinc.com | www.vertisinc.com

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


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