Skip to Content
author's profile photo Former Member
Former Member

JSP Instantiate Session Bean After Load

Hi Everyone,

I'm having a problem using a session bean in my jsp.

Sometimes, after I upload a par file, the first time I run the jsp, the jsp instantiates the session bean instead of using the one stored in the session.

I know the bean was correctly instantiated in my DynPage code because I wrote some of its information back to the jsp using IPortalComponentResponse object and I can see those.

I'm wondering if I need to change a property on my portalapp.xml file or on the portal itself.

Here is the component definition in my portalapp.xml:

<component name="NewRequest">


<property name="ClassName" value="com.nexeninc.tots.user.newrequest.NewRequest"/>

<property name="ComponentType" value="none"/>

<property name="JSP" value="pagelet/NewRequest.jsp"/>



<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>



One more thing, the problem is not recurring which is giving me grief to identify why and when exactly it is happening.

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2005 at 12:13 PM

    Hi Alaa,

    Just comment off this section

    <property name="ComponentType" value="none"/>

    <property name="JSP" value="pagelet/NewRequest.jsp"/>

    in the portalapp.xml file.It will work, you will get the values of the bean instance.



    Portal Consultant

    IBM Global Services India.


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Manab,

      I tried your suggestion but it didn't work.

      FYI, I can read the information from my jsp when I refresh the page. It's just the first time I upload my par file that I get this strange behaviour from the jsp.

      What makes it even more dazzling is that it does not happen consistently. It happens every two or three uploads. Any idea why?

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2005 at 09:59 AM

    Correct me if i'm wrong - but I think it is normal behaviour that the bean gets a new instance when you upload a new par file.

    Add a comment
    10|10000 characters needed characters exceeded

    • Not strictly. When you upload a new par file, the object that is written into the IPortalComponentSession is invalidated. It still exists as an object which is not null, however, if you try and cast the object into your type variable, then you will get a ClassCastException, which really needs to be caught.

      A new instance will then need to be created, and can only be created when the code is run. However, you can't predict when a garbage collection is run and this object is removed from the IPortalComponentProfile or IPortalComponentRequest. I have never had any problems with putting the object into the IPortalComponentSession though.

      I hope this helps


  • Posted on Oct 18, 2005 at 09:55 AM

    This may because of the place that you are storing the Bean object. You should be ok to store the bean in the IPortalComponentSession, however, I have seen instances that when you store the bean in the IPortalComponentProfile or IPortalComponentRequest that the Bean object is garbage collected, which can lead to very strange results

    I hope this helps


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2005 at 02:42 PM

    Thanks Darrell, Francisco for your answers.

    Darrell, I agree with you, putting a bean in the IPortalComponentSession should be fine. However the behaviour that I'm getting this time is strange.

    In my doInitialization() i'm creating a new bean object and store it in the session. After that the code simply call doProcessBeforeOutput() and point to the correct jsp. Nothing special in there.

    Here is my code to give you an idea of what I'm talking about:

    public void doInitialization(){

    componentSession = ((IPortalComponentRequest)getRequest()).getComponentSession();


    newRequestBean = new NewRequestBean((IPortalComponentRequest)getRequest());


    newRequestBean.appendDebugMessage("initialized page");


    public void doProcessBeforeOutput() throws PageException {

    if (newRequestBean.getState() == REQUEST) {


    } else {



    newRequestBean.appendDebugMessage("finished doProcessBeforeOutput");



    The bean I initiated in the doInitialization() is loaded with data that will populate my jsp. When the jsp calls the default constructor to instantiate my bean, I lose all that data.

    However, when I click to refresh the page, everything seems to work fine. The bean gets created just fine in the doInitialization(), loaded to the session and the jsp correctly reads that bean from the session instead of instantiating its own.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Darrell Merryweather

      The jsp code is too long so I'm posting the first part that include the declaration of the bean. Tell me if you want me to post the whole jsp.

      <%@ taglib uri="tagLib" prefix="hbj" %>

      <%@ page import="com.nexeninc.tots.user.newrequest.bean.*" %>

      <%@ page import="com.sapportals.htmlb.enum.EventTrigger" %>

      <%@ page import="java.util.Vector" %>

      <jsp:useBean id="newRequestBean" scope="session" class="com.nexeninc.tots.user.newrequest.bean.NewRequestBean" />

      <%! String newReqID; %>

      <%! String newCalculatedDayOff; %>

      <%! String startDateField; %>

      <hbj:content id="myContext" >

      <hbj:page title="PageTitle">

      <hbj:form id="frm" >

      <% if(newRequestBean.isDefaultConstructor()){

      Vector errors = newRequestBean.getValidationErrors();

      errors.add("The information couldn't be loaded, please refresh screen. "+

      "If problem persists, contact your system administrator.");





Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.