Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL Import not working  RSS feed

 
Dave Levitt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following data in a file called books.xml in my WEB-INF folder:
<?xml version="1.0"?>
<books>
<book>
<name>Padam History</name>
<author>ZARA</author>
<price>100</price>
</book>
<book>
<name>Great Mistry</name>
<author>NUHA</author>
<price>2000</price>
</book>
</books>

I'm using the following code in a jsp:
<c:import var="bookInfo" url="/WEB-INF/books.xml" />

I know that it's finding the file because if I delete books.xml from the WEB-INF folder I get a FileNotFound exception.

However, for some reason it doesn't appear to be importing the data into the bookInfo variable.
I noticed this problem because when I try to parse it via:
<x:parse xml="${bookInfo}" var="output"/>
I get org.xml.sax.SAXParseException: Premature end of file.

When I try to display the data in the variable either by:
<c:out value="${bookInfo}" />

...or by means of a scriptlet (which I realize is not a best practice):
<%
String myVariable = (String)pageContext.getAttribute("bookInfo");
System.out.print("bookInfo=" + myVariable);
%>

...I get nothing.

Anyone have a clue what's going on?

BTW when I do:
<c:import var="data" url="http://www.tutorialspoint.com"/>
<c:out value="${data}"/>

that works fine!

Any help much appreciated.



 
Dave Levitt
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
figured it out...

When I moved the file up one level from WEB-INF and changed the import to:
<c:import var="bookInfo" url="/books.xml" />
it worked.

Not sure why having the file in WEB-INF caused the problem, but at least I found a solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. As the import action uses a RequestDispatcher include() method to fetch the resource when it's internal to the web app, I would not have expected the file in WEB-INF to be a problem.

Welcome to the Ranch, Dave!

Thanks for posting back with your findings!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!