Including dynamic content in a JSP


Web tier: servlets, JSP, Web frameworks: Including dynamic content in a JSP

  1. Including dynamic content in a JSP (7 messages)

    Please read this mail carefully.I know this looks like something obvious but i am facins some serious problems because of the same.
    I have a jsp in which i want to include another HTML.Now i have the URL of this html in my session.I tried doing something like
    <jsp:include page =<%=session.getAttribute("XYZ")%> />

    the o/p in the corresponding HTML formed is :
    <jsp:include page ="/MYPath/abc.html" />

    And if i use a hard coded value for the page attribute as the one formed above it works fine...
    How do i then include the actual contents of the URL in my session.

  2. Did you try <jsp:include page =<%=session.getAttribute("XYZ").toString()%> />

    session.getAttribute() only return an object, if <%= %> hasn't overloaded to called toString(), you might need to call it yourself.
  3. Including dynamic content in a JSP[ Go to top ]

    I think you can try adding in quotation mark
    <jsp:include page =<%=session.getAttribute("XYZ")%> />
    <jsp:include page ="<%=session.getAttribute("XYZ")%>" />
  4. Hi,
    The value of the variable already contains the quotes needed.
    In any case i tried ur solution and the .toString too.
    Neither work :(
    what beats me is why isnt the jsp:include tag converted into servlet code ... It appears as is in the HTML

  5. <%String xyzHTML = (String)session.getAttribute("XYZ");%>

    <jsp:include page='<%=xyzHTML%>'/>
  6. because <jsp:include/> includes the page to be included when the page is loaded. if u want the page to be included in the generated servet, try using <@include src=""/>

  7. Hi,
    Got a solution.
    something like this works
    <% String s = session.getAttribute("XYZ") %>

    and then use
    <jsp:include page=<%=s%> />
    My question now is why does this work and not the prev one?
  8. first of all the code u gave doest work..
    coz session.getAttribute(String name) returns a object and has to be cast as a String.

    the code
    <jsp:include page="<%=(String)session.getAttribute("xyz")%>"/>
    should work.