aspose file tools*
The moose likes JSP and the fly likes JSTL XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL XML" Watch "JSTL XML" New topic
Author

JSTL XML

john adams
Greenhorn

Joined: May 13, 2008
Posts: 10
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">

<xut select="$n/title" /> <br>

<xut select="$n/author" /> <br>

========<br>
</x:forEach>
</body>
</html>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

<%@ 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 ]

Steve
john adams
Greenhorn

Joined: May 13, 2008
Posts: 10
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

Joined: May 13, 2008
Posts: 10
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
Aysha Qamar
Greenhorn

Joined: Jul 30, 2008
Posts: 5
Hi,

I've been getting the same exception,but instead of tomcat my app server is weblogic 8.1 . when i try to use xut 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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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 xut 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

Joined: Jul 30, 2008
Posts: 5
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

Joined: Jul 30, 2008
Posts: 5
And the x:parse and xut are now working fine with new libraries just the core c:set stopped working..
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

Joined: Jul 30, 2008
Posts: 5
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

Joined: Jul 30, 2008
Posts: 5
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
satya srinivas volla
Greenhorn

Joined: Oct 21, 2008
Posts: 3
[ 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 ]

srinivas
 
Consider Paul's rocket mass heater.
 
subject: JSTL XML