Need to pass info from servlet to jsp - Websphere

This is a discussion on Need to pass info from servlet to jsp - Websphere ; In my servlet I have: request.setAttribute("PageId", pageId); I do a forward: rd = request.getRequestDispatcher("/QP_MainDisplayPage.jsp"); rd.forward(request, response); In my jsp I try to do: Integer id = (Integer)request.getAttribute("PageId"); This statement throws a NullPointerException. This on WAS 6.1 on iSeries. The same ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Need to pass info from servlet to jsp

  1. Need to pass info from servlet to jsp

    In my servlet I have:

    request.setAttribute("PageId", pageId);

    I do a forward:

    rd = request.getRequestDispatcher("/QP_MainDisplayPage.jsp");
    rd.forward(request, response);

    In my jsp I try to do:

    Integer id = (Integer)request.getAttribute("PageId");

    This statement throws a NullPointerException. This on WAS 6.1 on
    iSeries.

    The same works perfectly when running on Tomcat. Anyone got any
    ideas ?



  2. Re: Need to pass info from servlet to jsp

    We do something similar in 5.1 on iSeries, and it works fine. The only
    difference is the way the servlet gets the dispatcher:

    this.getServletContext().getRequestDispatcher("myPage.jsp");

    Are you sure pageId is not null when you set it as an attribute?
    (Perhaps something is going wrong further upstream in WAS 6.1)

  3. Re: Need to pass info from servlet to jsp

    On 29 apr, 16:34, "walker.l2" wrote:
    > We do something similar in 5.1 on iSeries, and it works fine. The only
    > difference is the way the servlet gets the dispatcher:
    >
    > this.getServletContext().getRequestDispatcher("myPage.jsp");
    >
    > Are you sure pageId is not null when you set it as an attribute?
    > (Perhaps something is going wrong further upstream in WAS 6.1)


    There seems to be some differences with Tomcat and WebSphere. When we
    do the forward

    RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/
    view/ScreenFlowManager");
    rd.forward(request, response);

    and then try to read the requestUrl the result is different:

    request.getRequestURL().toString()

    In Tomcat: http://host/application/Controller/T...RequestAddPage
    In WebSphere: http://host/application/view/ScreenFlowManager

    It seems that WebSphere gives me the target URL, I forwarded to,
    instead of the original requestURL as if it does do a rewrap of the
    request.

    I found the following as a workaround:

    request.getAttribute("javax.servlet.forward.request_uri").toString()

    In both Tomcat and WebSphere I am getting http://host/application/Controller/T...RequestAddPage

    In my original problem, the orignal request is
    http://host/application/Controller/T...isplayMainPage. I did use
    the request.requestURL method, which gave me the wrong URL as
    explained and as a result lead to the null pointer exception.

    Since the requestURL method didn't work, I tried the getAttribute. But
    in this case that does not work either. In this particular case there
    are more servlets being passed. My conclusion is that at the time of
    reading the getAttribute is giving me the URL of the previous servlet.

    So if the chain is Servlet1 --> Servlet2 --> JSP and I try to read the
    original requestURL in the jsp itself

    TomCat will give me the URL of the orignal requestURL of servlet 1.

    WebSphere's requestURL will give me the targetURL of the jsp and the
    requestAtttribute will give me the URL of Servlet 2. But it won't give
    me the orignal requestURL from Servlet1.

    How to get the original request in WebSphere without setting it
    myself ?

+ Reply to Thread