0

I have a parent JSP that has widgets created using custom JSTL tags. To improve the page loading, I have used Jquery to dynamically load these widgets into Iframes. The source for the iframes is the widget code in separate JSP files.

So I created a JSP for each widget

$(function () {
           var widgetSrc = ["frame1.jsp", "frame2.jsp", "frame3.jsp", "frame4.jsp", "frame5.jsp", "frame6.jsp","frame7.jsp"];

       $.each(widgetSrc, function (index, element) {              
           var res = element.split(".");               
           var container = $("#"+res[0]);              
           appendNew(container, element);                  
       })
   })

Now in one of the widgets I need to access the HttpRequestrequest object to get few parameters.

In the parent jsp

<%= pageContext.findAttribute("sortBy") %> is giving the parameter value

in the frame1.jsp

<%= pageContext.findAttribute("sortBy") %> is always giving null

Please suggest how to pass the request object or the pagecontext of the parent.jsp to frame.jsp

Thanks in advance

Raviteja
  • 3,399
  • 23
  • 42
  • 69
VRK
  • 1
  • 2
  • [How do I format my posts using Markdown or HTML?](http://stackoverflow.com/help/formatting) – buhtz Dec 20 '16 at 11:45

1 Answers1

0
  1. pageContext is not request scope. It's page scope. Try <%=request.getParameter("sortBy")%> if the normal ${sortBy} or ${requestScope.sortBy} don't work.
  2. I expect iframes to have a different request scope.

You would be able to load the widget by jsp:include. If you need additional data than what already is set in request scope, you can use params.

<c:set var = "myWidget" value = "widget1"/>
<jsp:include page="${myWidget}.jsp" flush="true">
    <jsp:param name="sortBy" value="abc"/>
    <jsp:param name="myAttribute2" value="value2"/>
</jsp:include>

Note that you still won't find the attributes in pageContext, as you include a page with its own pageContext.

Here you can find a list of mechanisms to include content in JSP.

Neepsnikeep
  • 309
  • 3
  • 11