Hi,
My web application is using Struts with WebSphere 5.1. I have problems getting a Bean from http session. One of the action class creates and inserts a bean to http session and pass the the bean to a jsp page. The jsp page can't get it. The problem I found out so far is that I can't even get the bean in the action class once it's set by setAttribute (There is no problem to create the bean and put the bean into http session). I'd include the code pieces here for clarification.
public class joinStep1Action extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
// return value
HttpSession session = request.getSession();
try {
UserBean ub = (UserBean) session.getAttribute("user
Bean");
Map pbMap = new TreeMap();
if (ub != null) {
PaymentOptionsBean payOptBean = new PaymentOptionsBean(ub, pbMap);
if (payOptBean != null)
{
//session.setAttribute("pa
ymentOptio
nsBean",
// new PaymentOptionsBean(ub, pbMap));
session.setAttribute("paym
entOptions
Bean", payOptBean);
// pbMap is a Map of PricingBeans
session.setAttribute("pbMa
p", pbMap);
}
else {
System.out.println("Error!
!! setting paymentOptionsBean!!!");
}
}
PaymentOptionsBean pb = (PaymentOptionsBean)sessio
n.getAttri
bute("paym
entOptions
Bean");
System.out.println(pb.toSt
ring()); <---- getting java.lang.NullPointerExcep
tion
// Write logic determining how the user should be forwarded.
forward = mapping.findForward("succe
ss");
// Finish with
return (forward);
}
}
Please HELP!!!
Start Free Trial