This is probably a stupid newbie question, but I'm having a problem passing an object in the Request session from a Struts Action. If I place the object in "Session" scope it works fine. Everything I'm reading and the examples given show it should work fine [but it doesn't]. The error I keep receiving in my JSP is "Error 500: Cannot find bean cbnlist in any scope."
Here's my code:
Action.java
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.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.List;
public class getBrokerListingAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
HttpSession session = request.getSession(false);
try {
String search = ((BrokerListingForm)form).getSearch();
System.out.println("Search Criteria=" + search);
if(search == null) {search = "SMITH";}
List rs = DatabaseLookup.personLookup(search);
session.setAttribute("cbnlist",rs);
} catch (Exception e) {
// Report the error using the appropriate name and ID.
errors.add("name", new ActionError("id"));
}
return mapping.findForward("success");
}
}
JSP file
<%@ page language="java" %>
<%@taglib uri="/tags/struts-html" prefix="html"%>
<%@taglib uri="/tags/struts-bean" prefix="bean"%>
<%@taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html>
<body style="margin-top: 0px; margin-left: 0px">
<html:errors />
<html:form action="getBrokerListing" focus="search" >
<html:text property="search" size="16" />
<html:submit>
<bean:message key="button.submit" /></html:submit>
</html:form>
<logic:iterate id="bbo" name="cbnlist">
Name: <bean:write name="bbo" property="firstname" /> <bean:write name="bbo" property="lastname" /><br>
Pbno: <bean:write name="bbo" property="pbno" /><br>
</logic:iterate>
</body>
</html:html>
Struts-Config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- ==================================== Data Source Configuration -->
<!-- ======================================== Form Bean Definitions -->
<form-beans>
<form-bean
name="brokerListingForm"
type="cbn.generic_view.BrokerListingForm" />
<form-bean
name="brokerShortList"
dynamic="true"
type="org.apache.struts.action.DynaActionForm">
<form-property name="cbnlist" type="cbn.generic_view.BrokerBaseObject" />
</form-bean>
</form-beans>
<!-- ================================= Global Exception Definitions -->
<global-exceptions>
</global-exceptions>
<!-- =================================== Global Forward Definitions -->
<global-forwards>
<forward
name="mainpage"
path="getBrokerListing.do" />
</global-forwards>
<!-- =================================== Action Mapping Definitions -->
<action-mappings>
<action
path="/getBrokerListing"
type="cbn.generic_view.getBrokerListingAction"
name="brokerListingForm"
scope="session"
validate="false" >
<forward name="success" path="/pages/broker_listing.jsp" redirect="true" />
<forward name="failure" path="/pages/licensing.jsp" redirect="true">
</forward>
</action>
</action-mappings>
<!-- ===================================== Controller Configuration -->
<controller
contentType="text/html;charset=UTF-8"
debug="3"
nocache="true"
processorClass="org.apache.struts.action.RequestProcessor"/>
<!-- ================================ Message Resources Definitions -->
<message-resources
parameter="resources.application" />
<!-- ======================================= Plug Ins Configuration -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
</struts-config>
Any help would be greatly appreciated.
-
Passing Request session object in Struts (3 messages)
- Posted by: Chris Smith
- Posted on: June 09 2004 15:23 EDT
Threaded Messages (3)
- Passing Request SCOPE object in Struts by Chris Smith on June 09 2004 15:26 EDT
- Passing Request SCOPE object in Struts by Paul Strack on June 09 2004 19:41 EDT
- That worked! Thanks. by Chris Smith on June 10 2004 09:12 EDT
- Passing Request SCOPE object in Struts by Paul Strack on June 09 2004 19:41 EDT
-
Passing Request SCOPE object in Struts[ Go to top ]
- Posted by: Chris Smith
- Posted on: June 09 2004 15:26 EDT
- in response to Chris Smith
Sorry, gang. I meant to say Request SCOPE, not session. -
Passing Request SCOPE object in Struts[ Go to top ]
- Posted by: Paul Strack
- Posted on: June 09 2004 19:41 EDT
- in response to Chris Smith
Sorry, gang. I meant to say Request SCOPE, not session.
In that case, here is your problem:
<forward name="success" path="/pages/broker_listing.jsp" redirect="true" />
If you specify redirect="true", Struts uses a client-side redirect [response.sendRedirect()]. The JSP will be invoked by a new browser request, and any data stored in the old request will be lost.
Your options are:
1) Store the data in session scope.
2) Don't set redirect="true". -
That worked! Thanks.[ Go to top ]
- Posted by: Chris Smith
- Posted on: June 10 2004 09:12 EDT
- in response to Paul Strack
That helps a lot. Thanks Paul.
Chris