• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSTL XML

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been beating my head against the wall trying to get a simple jsp file to display a simple xml file in a table.
Simple right? Answer: NO-WAY!
Even the simple examples on the internet (e.g. http://www.roseindia.net/jstl/jstlxmltags.shtml ) does'nt work. All I'm getting are errors.
Is JSTL XML broken? Is there some java class package import I need to make to get things working?

What's the xml trick?

Simple example from http://www.roseindia.net/jstl/jstlxmltags.shtml

books.xml
-------------
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<title>cobol</title>
<author>roy</author>
</book>
<book>
<title>java</title>
<author>herbert</author>
</book>
</books>

demo1.jsp
-------------
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" >uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<body>
<c:import url="books.xml" var="url" />
<x:parse xml="${url}" var="doc" />

-----------------------------------------------<br>

<x:forEach var="n"
select="$doc/books/book">

<x:out select="$n/title" /> <br>

<x:out select="$n/author" /> <br>

========<br>
</x:forEach>
</body>
</html>
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things:

1) "It doesn't work" is not useful. What errors are you getting?

2) Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<%@ taglib prefix="c" >uri="http://java.sun.com/jsp/jstl/xml" %>


Should be

<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>




Also a few things to clear up. The code has:
<c:import url="books.xml" var="url" />
As if what the c:import is doing is providing a URL for the x:parse to read and parse. It is actually reading the entire file into a string, and providing that String to x:parse to read.

The xml attribute for the x:parse tag is deprecated, you should use the doc attribute instead:
<x:parse doc="${url}" ... />

And you may have to download and install Xalan from Apache, depending on if your server doesn't already have it (which Tomcat 6 didn't).

-- pet peeve: Tutorial sites that provide non-working code.
[ July 27, 2008: Message edited by: Steve Luke ]
 
john adams
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,

After making the <x:parse doc="${url}" var="doc /> change. I dropped xalan.jar, xercesimpl.jar and xml-apis.jar into <apache-tomcat dir>/lib folder, and corected the taglib mistake,
I ran the program in Netbeans 6.1 and received the following error(s):

java.lang.NoClassDefFoundError: org/apache/xpath/XPathException
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by john adams:
Hi Steve,

After making the <x:parse doc="${url}" var="doc /> change. I dropped xalan.jar, xercesimpl.jar and xml-apis.jar into <apache-tomcat dir>/lib folder, and corected the taglib mistake,
I ran the program in Netbeans 6.1 and received the following error(s):

java.lang.NoClassDefFoundError: org/apache/xpath/XPathException



Move the JARs to $Catalina_Base/endorsed rather than $Catalina_Base/lib. The JDK comes with its own version of the XML parsers that are not compatible with Apache's implementation of the the JSTL XML tags (legacy reasonses). To override this, put your JARs in the endorsed folder rather than the lib folder.
 
john adams
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THAT DID IT! HURAH! HURAH! HURAH!

Thanks Steve (x 1 million). I never would have have that solution because I never new about the <apache-tomcat>/endorse folder, since it's not included as a folder in Tomcat 6. But I created it and droped the 3 xalan files into it, booted up Netbeans, ran it and HURAH! HURAH! HURAH!

Thanks again
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've been getting the same exception,but instead of tomcat my app server is weblogic 8.1 . when i try to use x:out it gives me xpath problem. can you please tell me where to drop xalan.jar into weblogic to get rid of this error.

Thanks alot,
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aysha Qamar:
Hi,

I've been getting the same exception,but instead of tomcat my app server is weblogic 8.1 . when i try to use x:out it gives me xpath problem. can you please tell me where to drop xalan.jar into weblogic to get rid of this error.

Thanks alot,



I don't know about Weblogic, it may override the endorsed folder or not. Try using <Java Home>/lib/endorsed
 
Aysha Qamar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.. its not working.. even if i put the endorsed folder in jdk lib. i tried using new libraries JSTL 1.1.2 instaed of 1.0 but now its giving me errors in using EL variables such as c:set it gives me errors like

java.lang.InternalError: erroneous handlers
at jsp_servlet._web_45_inf._pages._saab.__warrantiesss._jspService(footer.jsp:15)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:375)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at com.fjord.webapp.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:42)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:72)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:334)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:375)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)


Please help me....Thanks alot..
 
Aysha Qamar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the x:parse and x:out are now working fine with new libraries just the core c:set stopped working..
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never seen that error before.

What version of the web application spec are you using? Look at the top of the web.xml to see.

What version of the web application spec does your version of Weblogic support? See their documentation

What URI are you using for the core (c:) taglib?
 
Aysha Qamar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The web.xml version is 2.4 which apparently weblogic 8.1 supports and the uri is <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>..
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aysha Qamar:
The web.xml version is 2.4 which apparently weblogic 8.1 supports and the uri is <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>..



That all looks good. Have no clue what the problem is. Try re-downloading JSTL tags. If you are using JSTL 1.1 put both the jstl.jar and standard.jar in your application's /lib directory.

Other than that, I can't help.
 
Aysha Qamar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its Ok! thanks a lot Steve for your time.. I've decided to switch to digester for parsing xmls instead of using JSTL.

Thanks once again
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[ UD: Please do not post unrelated questions into existing threads. That's called hijacking, and is considered a not so nice thing to do. ]
[ October 21, 2008: Message edited by: Ulf Dittmer ]
 
I love a good mentalist. And so does this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic