JSP/JSTL & XML

I am trying to have JSP pages parse and read an XML file and then return some data in an HTML table. I'm using the JSTL libraries and have a basic understanding of them, but I apparently need help.
My first page just gets the value and passes it to the second page. The second page handles all of the processing. Here is my JSP page:
<%@page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@include file="index.jsp" %>
<% String clientID = request.getParameter("enteredID"); %>
<c:import url="npiXMLTest5.xml" var="doc" />
<x:parse varDom="dom" doc="${doc}"/>
<x:set var="srcCID" select="string($dom/npiNumbers/client/clientNum)" />
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NPI XJTL Test</title></head>
<body>
<c:set var="CID" value="<%= clientID %>" />
<h2>NPI XJTL Test Page</h2>
<table border="1">
<tr><th>NPI Number</th><th>Description</th></tr>
<c:choose>
<c:when test="${CID}=${srcCID}">
<x:forEach select="$dom/npiNumbers/client/npiNum" var="$n">
<tr><td><x:out select="$n/npi" /></td><td><x:out select="$n/desc" /></td></tr>
</x:forEach>
</c:when>
<c:otherwise>
There is an error with your coding
</c:otherwise>
</c:choose>
</table></body></html>My XML structure is as follows:
<npiNumbers xsi:schemaLocation="http://localhost/namespace NPI_XSD5.xsd" xmlns="http://localhost/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<client>
<clientNum/>
<clientName/>
<npiNum>
<npi/>
<desc/>
</npiNum>
</client>
</npiNumbers>I am trying to return the results of the <npiNum> element (which can have multiple values) - <npi> and <desc> - in a table based on the <clientNum> element. I try to evaluate the page variable with the xml element. If it matches, I will return a table. A client can have multiple <npiNum> elements, so the construction of the table is in the x:forEach loop.
I think my problem is getting the variable from JSP to compare against the <clientNum> element in the XML file.
Any ideas?

I think your problem is less JSP/JSTL and more querying the XML.
You are trying to "select all <npinum> elements from a client based on clientnum"
I am far from an expert on XPath, but I think the following query is what you are after: "/npinumbers/client[clientNum=????]/npiNum"
To do that with JSTL you would replace ???? with $param:enteredId or $CID (equivalent in your example)
Here is the resulting JSP page.
<%@page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import url="npiXMLTest5.xml" var="doc" />
<x:parse varDom="dom" doc="${doc}"/>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NPI XJTL Test</title></head>
<body>
<c:set var="CID" value="${param.enteredId}" />
<h2>NPI XJTL Test Page</h2>
<table border="1">
<tr><th>NPI Number</th><th>Description</th></tr>
<x:forEach select="$dom/npiNumbers/client[clientNum=$CID]/npiNum" var="n">
  <tr><td><x:out select="npi" /></td><td><x:out select="desc" /></td></tr>
</x:forEach>
</table>
<hr>
<form>
<input type="text" name="enteredId"/>
<input type="submit">
</form>
</body></html>I made up the following test file to use with it. I don't know if it was exactly what your requirements are, but it was a best guess based on your info.
<npiNumbers>
     <client>
          <clientNum>42</clientNum>
          <clientName>Ford Prefect</clientName>
          <npiNum>
               <npi>123</npi>
               <desc>life</desc>
          </npiNum>
          <npiNum>
               <npi>234</npi>
               <desc>universe</desc>
          </npiNum>
          <npiNum>
               <npi>456</npi>
               <desc>everything</desc>
          </npiNum>          
     </client>
     <client>
          <clientNum>666</clientNum>
          <clientName>Satan</clientName>
          <npiNum>
               <npi>333</npi>
               <desc>Baby Devil</desc>
          </npiNum>
     </client>
</npiNumbers>Cheers,
evnafets

Similar Messages

  • Working sample of JSTL:xml?

    Can someone send me a working sample war file using jstl:xml under JSTL 1.1/tomcat 5?
    I think my JSP is right, but I tried it on tomcat-5.5.4, 5.0.28 with JDK1.4.2, JDK1.5.0. All of them give me [#document: null] result. There must be something wrong in my configuration.
    If someone can send me a working war file, I would really appreciate.
    My email address: [email protected]
    Thanks!

    Okay, it is clear to me, you are thinking something that may be working is not, because you are testing incorrectly.
    Doing a c:out of the variable returned from <xml:parse> and getting [#document:  null] is not a sign that the xml document wasn't parsed. I am not sure exatly what the null part of the output means but...
    Look at this code:
    //Sidebar.xml
    <?xml version="1.0"?>
    <home_bar>
        <bar_width>250</bar_width>
        <button_height>30</button_height>
        <button_width>200</button_width>
        <button_img>images/norm_button.gif</button_img>
        <button_list>
          <button id="1">
            <link_url>./</link_url>
            <text>Home</text>
          </button>
          <button id="2">
            <link_url>/Calendar</link_url>
            <text>Calendar</text>
          </button>
          <button id="3">
            <link_url>/Calendar/howto.jsp</link_url>
            <text>How To Use the Calendar</text>
          </button>
          <button id="4">
            <link_url>/Webmail</link_url>
            <text>Webmail</text>
          </button>
          <button id="5">
            <link_url>/Webmail/howto.jsp</link_url>
            <text>Webmail HowTo</text>
          </button>
          <button id="6">
            <link_url>/Web/howto.jsp</link_url>
            <text>How To Make a Web Page</text>
          </button>
          <button id="7">
            <link_url>/HTML/howto.jsp</link_url>
            <text>Learn HTML</text>
          </button>
          <button id="8">
            <link_url>/JS/howto.jsp</link_url>
            <text>Learn JavaScript</text>
          </button>
        </button_list>
    </home_bar>
    //Sidebar.jsp
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
      <c:import var="sideBarXml" url="Sidebar.xml" />
      <x:parse doc="${sideBarXml}" var="sideBar" />
      <%-- Show that the side bar was read --%>
        <!-- Side Bar = <c:out value="${sideBar}"/> -->
      <%-- End of Test Output --%>
      <x:set var="theBar" select="$sideBar/home_bar"/>
      <style type="text/css">
        .sidebar
          width  : <x:out select="$theBar/bar_width"/>px;
          float  : left;
          clear  : left;
        .button
          background : transparent url(<x:out select="$theBar/button_img"/>) no-repeat scroll center;
          height     : <x:out select="$theBar/button_height"/>px;
          width      : <x:out select="$theBar/button_width"/>px;
          cursor     : pointer;
          float      : left;
          clear      : left;
          text-align : center;
          color      : white;
      </style>
      <div class="sidebar">
         <x:forEach select="$theBar/button_list/button" var="button" varStatus="status">
           <div class="button" onclick="document.location='<x:out select="$button/link_url"/>';">
             <x:out select="$button/text"/>
           </div>
         </x:forEach>
      </div>
    //index.jsp
    <html>
      <head>
        <title>Showing JSTL:XML tags</title>
        <style type="text/css">
          DIV.content
            disaplay: block;
            float   : left;
            clear   : right;
            width   : 500px;
            font-family: Serif;
        </style>
      </head>
      <body>
        <jsp:include page="Sidebar.jsp"/>
        <div class="content">
          Just some things to show for the content of the JSP...
        </div>
      </body>
    </html>
    //WEB-INF/web.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
        version="2.4">
      <display-name>XML Display Application</display-name>
    </web-app>
    //HTML Output
    <html>
      <head>
        <title>Showing JSTL:XML tags</title>
        <style type="text/css">
          DIV.content
            disaplay: block;
            float   : left;
            clear   : right;
            width   : 500px;
            font-family: Serif;
        </style>
      </head>
      <body>
        <!-- Side Bar = [#document: null] -->
      <style type="text/css">
        .sidebar
          width  : 250px;
          float  : left;
          clear  : left;
        .button
          background : transparent url(images/norm_button.gif) no-repeat scroll center;
          height     : 30px;
          width      : 200px;
          cursor     : pointer;
          float      : left;
          clear      : left;
          text-align : center;
          color      : white;
      </style>
      <div class="sidebar">
         <div class="button" onclick="document.location='./';">
             Home</div>
         <div class="button" onclick="document.location='/Calendar';">
             Calendar</div>
         <div class="button" onclick="document.location='/Calendar/howto.jsp';">
             How To Use the Calendar</div>
         <div class="button" onclick="document.location='/Webmail';">
             Webmail</div>
         <div class="button" onclick="document.location='/Webmail/howto.jsp';">
             Webmail HowTo</div>
         <div class="button" onclick="document.location='/Web/howto.jsp';">
             How To Make a Web Page</div>
         <div class="button" onclick="document.location='/HTML/howto.jsp';">
             Learn HTML</div>
         <div class="button" onclick="document.location='/JS/howto.jsp';">
             Learn JavaScript</div>
         </div><div class="content">
          Just some things to show for the content of the JSP...
        </div>
      </body>
    </html>The WEB-INF/lib directory contains jstl.jar and standard.jar (JSTL 1.1.1 I think). Nothing but basic Tomcat 5.0.29 installed in the common directories. JDK1.4 installed.
    Anyway, from the output, you can see in the comment inside the HTML source that the c:out for the parsed XML file reads [#document: null]. However, the XML was correctly parsed and generated the proper sidebar.
    I know that if you do something like this:
    <x:set var="theBar" select="$sideBar/home_bar"/>
    <c:out value="${theBar}"/> you get [[home_bar: null]].
    Also, if you do:
    <x:out select="$sideBar"/> you will get all the data from the xml file (not the tags) printed out.

  • JSTL XML problem

    I use Tomcat 5.5.4, Jarkata JSTL 1.1.2, here is what I do:
    (1) copy JSTL jar (standard.jar, jstl.jar) to tomcat common/lib directory
    (2) create a jsp page like:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    <c:import var="data" url="sample.xml" />
    <x:parse var="res" doc="${data}" />
    if I print ${data}, it is correct XML file as I expected. But I always get [document:null] as XML parsing result.
    Besides, whatever JSTL XML function I try, seems all of them give me error or null result.
    Is there any special setting that I miss?
    Why JSTL:core works and JSTL:xml doesn't?
    Anyone have suggestion? Thanks!

    To answer your questions from the previous post: No, I don't have Xalan.jar anywhere, unless it is packaged inside of some other jar, like one of the commons jars.
    I am using Tomcat 5.0.29 or real close to it. Java 1.4.2.
    A further question:
    Do I really need copy c.tld and x.tld to WEB-INF/ and
    set them up in WEB-INF/web.xml?
    No. The tlds inside the JARs are all you need. I would get rid of these copies.
    My understanding is: since you specify that uri:
    http://java.sun.com/jsp/jstl/core, there is no need
    to copy and set-up tld.
    At least, if I remove them, JSTL:core works fine. As
    for JSTL:xml, it doesn't work either way.What version of the web descriptor are you using? Version 2.3 or 2.4? It should either be defined is a <?DOCTYPE... ?> tag (v 2.3) or in the <web-app ...> tag (v. 2.4). You should be using the vs. 2.4.
    I don't know if that would make a difference though...

  • Problem using JSTL XML tags.

    My xml tag is giving problems. All other tags (core/sql and EL) are working fine. Even a very simple code like :
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!-- parse an XML document -->
    <x:parse var="simple">
    <a>
    <b>
    <c>C </c>
    </b>
    <d>
    <e> E </e>
    </d>
    </a>
    </x:parse>
    <!-- display using XPath expressions -->
    <x:out select="$simple//e"/>
    gives error as :
    javax.servlet.ServletException: Cannot inherit from final class
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
         org.apache.jsp.jsp.xml.first_jsp._jspService(first_jsp.java:65)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    Pls. help!

    Works with no problems for me. (same exact code posted into a JSP)
    Running on Tomcat 5, Java1.4
    What server are you running, and version of java?
    Is there anything else on the page? Are you extending a class somehow?
    Do you have any extra libraries in the web-inf/lib directory that might be conflicting?

  • JSP, JSTL and XML Exception

    Hi,
    I'm using tomcat 5.0.28 with J2SE5, JSP and JSTL. I tried to execute the following example about JSTL and XML.
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
    <c:import url="book.xml" var="url" />
    <x:parse xml="${url}" var="book" scope="session" />
    <x:choose>
    </x:choose>
    <P>
    <B><x:out select="$book/book/title"/></B><BR>
    <x:out select="$book/book/author"/><BR>
    <x:out select="$book/book/url"/><BR>When I execute the jsp file, the container produces following exception:
    javax.servlet.ServletException: org/apache/xpath/XPathException
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
         org.apache.jsp.xml.xml_005fchoose_jsp._jspService(xml_005fchoose_jsp.java:104)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.lang.NoClassDefFoundError: org/apache/xpath/XPathException
         java.lang.ClassLoader.defineClass1(Native Method)
         java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
         org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         org.apache.taglibs.standard.tag.common.xml.WhenTag.condition(WhenTag.java:51)
         org.apache.taglibs.standard.tag.common.core.WhenTagSupport.doStartTag(WhenTagSupport.java:65)
         org.apache.jsp.xml.xml_005fchoose_jsp._jspx_meth_x_when_0(xml_005fchoose_jsp.java:203)
         org.apache.jsp.xml.xml_005fchoose_jsp._jspx_meth_x_choose_0(xml_005fchoose_jsp.java:169)
         org.apache.jsp.xml.xml_005fchoose_jsp._jspService(xml_005fchoose_jsp.java:84)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    Due to the fact, that org/apache/xpath/XPathException belongs to xalan, i copied the xalan 2.7.0 to the web-inf/lib directory. But this doesn't solve the problem. I'm tried it also with xalan, xerces and jaxp. Again, it doesn't work.
    Can anybody help me with this problem?
    bye

    Couple of things, possibly unrelated, but not sure.
    You are using JSTL1.0 uris.
    With Tomcat5 you can use JSTL1.1, and the Servlet2.4 spec.
    You would use the URI: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    and also update your web.xml file to declare itself as version 2.4
    You shouldn't need any of the xalan xerces or jaxp classes in web-inf/lib.
    xerces is by default found in the [TOMCAT]/common/endorsed directory.
    The others should be provided with the standard java API.
    I would try with minimal jar files in web-inf/lib
    Occasionally if you include files twice in the classpath it will create ClassNotFoundExceptions like this.
    Hope this helps,
    evnafets

  • Build XML Document in Servlet use JSTL xml tags in JSP

    Is it possible to build an XML document either org.w3c.dom.Document or preferably org.jdom.Document in a Servlet and pass it as a Bean or Bean property to a JSP and use it in the JSTL xml tags? If so how is it done? I don't want to write the document out to a file.
    Thanks
    Mark

    Both DOM and JDOM allow you to serialize XML to an output stream. Use the StringWriter as the output stream and when its finished you will have the XML in a String. Put the String in the Request scope and your JSP should be able to see it.

  • How to count number of xml nodes , with JSTL XML api?

    I am trying to count the number of nodes in the parsed xml by doing this:
    <x:out select="count($doc/Items/Item)"/>
    There are about 50 item nodes in the source xml, but I get the output as 0
    Is this syntax correct?
    I searched every where but couldn't find the xpath syntax to be used inside jstl xml tags, I was assuming that it's the same as the syntax used in xslt

    Thank you for your reply, sorry I wasnt very clear with my question.
    I want to count the number of nodes inside the jsp file , not inside the xslt file.
    My xml file is something like this for example:
    <?xml version="1.0" encoding="UTF-8"?>
    <DocumentRootNode>
    <Products>
    <Item>1</Item>
    <Item>2</Item>
    <Item>3</Item>
    <Products>
    </DocumentRootNode>
    I want the count of number of Item nodes , in the JSP file.
    I'm doing something like this in the JSP but it gives 0 instead of 3:
    <c:import url="source.xml" var="xml" charEncoding="UTF-8"/>
    <x:parse doc="${xml}" var="xml_doc"/>
    <x:out select="count($xml_doc/Products/Item)"/>
    null

  • Class not found javax.servlet.jsp.jstl.sql.Result in Richfaces

    When I try to run the richfaces application using Weblogic 10.3 AS and Netbean IDE 6.9.1, I found ClassNotFoundException on javax.servlet.jsp.jstl.sql.Result class.
    I class path the following libs.
    commons-beanutils-core-1.8.0.jar
    commons-digester-1.8.jar
    commons-fileupload-1.2.1.jar
    commons-io-1.2.jar
    commons-logging-1.1.1.jar
    glassfish.el_2.1.1.jar
    glassfish.jsf_1.2.9.0.jar
    javassist-3.8.0.GA.jar
    jhighlight-1.0.jar
    jsf-facelets.jar
    jsf-api.jar
    log4j-1.2.14.jar
    richfaces-api-3.3.0.GA.jar
    richfaces-impl-3.3.0.GA.jar
    richfaces-ui-3.3.0.GA.jar
    glassfish.jstl_1.2.0.1.jar
    Also I try to deploy without using some jar files already exists in application server.
    My web.xml configuration is-
    <context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>#{skinSelector.skin}</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
    </context-param>
    <context-param>
    <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
    <param-value>com.sun.facelets.FaceletViewHandler</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>
    <context-param>
    <param-name>org.ajax4jsf.SKIN</param-name>
    <param-value>skin_name</param-value>
    </context-param>
    <filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <login-config>
    <auth-method>BASIC</auth-method>
    </login-config>
    <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    I also try to configure <library-ref>....</libray-ref> configuration in weblogic.xml and weblogic-application.xml and I also deploy JSF-2.0.war as library in application.
    Please
    h5.MUTU

    So why didn't you think that the JSP forum here wasn't a good place to ask JSP questions like this one?
    You can use <c:for-each> with a List. That's how it's designed. I don't understand why you say you can't. Perhaps you were confused by the SQL tags in JSTL. But anyway, you should just return a List from your EJB and forget about using obscure internal JSP classes.

  • Jstl xml parser not working

    i cant seem to be able to select the values from the imported xml file and i dont understand why?
    my jsp page:
    <%@ page import="java.util.*;" %>
    <%@ page contentType="text/html; charset=ISO-8859-5" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <html>
    <head>
        <title>Interactive Experience Database - Template 1</title>
        <LINK REL="STYLESHEET" TYPE="text/css" HREF="style.css">
    </head>
    <body>
    <FORM>
    <c:import var="xmlfile" url="/cv.xml"/>
    <x:parse var="doc" xml="${xmlfile}"/>
    <x:out select="$doc/cv/ContactInfo/PersonName"/>
    </form>
    </body>
    </html>the xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cv>
    <cv>
    <ContactInfo>
         <PersonName>Donald Smith</PersonName>
    </ContactInfo>
    </cv>

    thanks, one thing that annoys me is that that apache
    make it so hard to download anything, finding the
    binary is so time consuming, ive been looking for the
    last half hour. its a jokeI kind of agree with you that for certain projects it is a little difficult to find the stable release of the binaries. I personally find it very time consuming to locate the binary for JSTL 1.1 , and finding the binary for Xalan seems a little more easier than finding the one for JSTL 1.1
    For Xalan I was quickly able to locate it through google:
    Searched for "download apache xalan" , then Google showed me
    http://xml.apache.org/xalan-j/downloads.html then I clicked on :
    http://www.apache.org/dyn/closer.cgi/xml/xalan-j
    ~~~~~~~~~~~~~~~~~~~~~~
    But for JSTL 1.1 it took quite a number of steps :
    Searched on Google for : "download JSTL 1.1"
    First link showed:
    http://java.sun.com/products/jsp/jstl/downloads/index.html
    Shows the link for Standard 1.0 instead of Standard 1.1
    (A newbie to JSTL wouldn't know that there's a 1.1 final release download available)
    another link for the same keywords takes me to:
    http://jakarta.apache.org/taglibs/
    Then I click on downloads: http://jakarta.apache.org/taglibs/#Downloads
    but it only shows Nightly Builds downloads not the stable release ones.
    Then I click on JSTL1.1 on the left nav takes me to
    http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html
    The download link finally takes me to:
    http://people.apache.org/builds/jakarta-taglibs/nightly/
    which is again nightly
    Then I carefully read and finally see:
    Download the Binary Distribution of the Final Release:
    http://jakarta.apache.org/site/downloads/index.html
    Then I click on TagLibs
    http://jakarta.apache.org/site/downloads/downloads_taglibs.html
    and pick Standard 1.1 Tag lib (assuming that is JSTL 1.1)
    http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi
    I guess I could report this issue to Apache Taglibs and have them make it more efficient to locate the download for the Taglibs.

  • Problem in using request parameters in jstl xml code

    hi,
    my need is to get a request parameter and use the variable in jstl(xml) select conditions.
    my code is ,
    <%String txname=request.getParameter("tname");%>
    <x:forEach var="fe" select="$doc/transaction/tx[@tname=${txname}]/field">
         <field>ss <x:out select="$fe/@fname"/> </field>
    </x:forEach>
    i'm using tomcat5.0. I deployed the jstl.jar, standard.jar, jaxen.jar and saxpath.jar in WEB-INF/lib directory.
    I able to run other jstl(xml) files which doesn't need any variables from out side.
    i used the scirpt for getparameter as i unable to get the code ${param.tname}
    help me.
    urs
    pavan.

    Looks like you haven't imported the taglib:
    JSTL1.0: <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    JSTL1.1: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    You use JSTL1.0 in JSP1.2 containers (eg Tomcat 4)
    You use JSTL1.1 in JSP2.0 containers (eg Tomcat 5)
    also check this post if you have further troubles. It has basic troubleshooting for JSTL.

  • JSP/JSTL configuration

    I realize this is an often repeated topic. But, after having reviewed some threads on configuring this I still have the same issue.
    Must be missing something easy.
    I am using Tomcat 6.x and working with Spring 2.5 and trying to get my JSP's to use JSTL 1.1.2.
    The standard.jar and jstl.jar are both in the WEB-INF/lib of my application.
    I am getting the following error...
    /index.jsp(1,1) The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)Here is my web.xml declaration.
    <web-app version="2.4"
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >Here is the include.jsp URI's
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>What am I doing incorrectly? Thanks for your help!

    From what you have shown here, you aren't doing anything wrong as far as I can tell.
    The error message is reporting it can't find a tld that declares that uri.
    That would imply that the tld file is not there - ie it can't find standard.jar in the classpath
    Make sure you downloaded the correct version of JSTL.
    JSTL1.1: [jakarta site|http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi]
    JSTL1.2: [java.net / glassfish|https://jstl.dev.java.net/download.html]
    Either should work with Tomcat6.
    You say you have the jar files in your WEB-INF/lib directory.
    Open standard.jar with any standard zip tool.
    You should be able to see a number of .tld files in this zip file. eg c.tld, c-1_0.tld
    Take a look at the MANIFEST.MF file to see what version you have, and what specification it implements.
    Is your WEB-INF/lib directory in the right place? Where does it sit in relation to the Tomcat webapps directory?
    cheers,
    evnafets

  • JSPs as XML Documents -- Problems

    Hi --
    Have been following the spec for JSP as XML documents because I want to produce JSPs using XSLT. Two problems which I've yet to find anything but workarounds for:
    1. (Most pressing) JSP Documents do not allow this <%= blah %>. This creates problems when I want to dynamically create an attribute value. The spec recommends this: 'value = "%=var%"', but I've tried this in Tomcat 4.1.12 and the expression gets reproduced literally at run-time. I've searched these forums and not found an answer.
    2. Transformer wigs out on colons in "jsp:root" or "c:out" because it signifies a namespace with which it is unfamiliar. It doesn't need to recognize the namespace. Right now I'm putting in placeholders (jsp999root, for example) and replacing them after processing. Is there a better way?
    These problems are really getting in the way. Any help would be most appreciated.

    Hi,
    It looks from No. 2 that you are using JSLT since you have a fragment of a <c:out tag. I believe the syntax for getting the value out of one of these tags is actually almost identical to that in XSLT:
    value="${var}" instead of what you got from the spec,
    The spec recommends this: 'value = "%=var%"'The name spaces do have to be declared for JSLT to work, declared in the <jsp:root> tag:
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:c="http://java.sun.com/jstl/core"
    version="1.2">
    Here's a very simple jsp that uses it:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:c="http://java.sun.com/jstl/core"
    version="1.2">
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <html>
         <head>
         <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
         <title>Hello World</title>
         </head>
         <body>
         <c:set var="nameString" value="John"></c:set>
         <h2>The name is: <c:out value="${nameString}"/></h2>
         </body>
    </html>
    </jsp:root>
    Of course, you have to have the tlds set up and the JSLT jars available for the compiler.
    I haven't yet tried this with transforms, but there are tags in the JSLT for that as well. If you've tried all this already, my apologies.
    Edward

  • JSTL javax.servlet.jsp.jstl.core.Config strange lookup

    Hi everyone !
    Could someone explain me this code in the class javax.servlet.jsp.jstl.core.Config :
    public static Object get(PageContext pc, String name, int scope) {
    switch (scope) {
         case PageContext.PAGE_SCOPE:
         return pc.getAttribute(name + PAGE_SCOPE_SUFFIX, scope);
         case PageContext.REQUEST_SCOPE:
         return pc.getAttribute(name + REQUEST_SCOPE_SUFFIX, scope);
         case PageContext.SESSION_SCOPE:
         return get(pc.getSession(), name);
         case PageContext.APPLICATION_SCOPE:
         return pc.getAttribute(name + APPLICATION_SCOPE_SUFFIX, scope);
         default:
         throw new IllegalArgumentException("unknown scope");
    Why adding a suffix when calling PageContext.getAttribute(String, int) ?
    This could lead to potential problems... For example, in my web application I want to share a single ResourceBundle for each JSP page and I would like to use <fmt:message/> tag to resolve my messages.
    For this purpose I added a LocalizationContext in my servlet context attribute in its init method:
    ResourceBundle bundle = ....
    LocalizationContext context = new LocalizationContext(bundle);
    servletContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT, context);
    Thus, the <fmt:message/> will be able to resolve the messages from this LocalizationContext...
    Unfortunately, this will never happen because the implementation of this tag call somewhere Config.find(PageContext, String) that will call the Config.get(PageContext, String, int) method....
    A quick fix would be to replace the name of the servlet context attribute :
    servletContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".application", context);
    Could someone tell me if it is a bug ? A bug of the Message tag implementation ? A bug in JSTL code ? Or am I doing all wrong ?
    Note : I'am using a servlet 2.4/JSP 2.0 compatible application with the jstl 1.2 core library and the jakarta standard 1.1.2 implementation library. I'am using Jetty to test my application with Jasper as the JSP compiler...

    This is an internal decision made by JSTL as to how it stores its configuration values.
    The reason they have given here for the suffixes being added is to treat the four scopes as different namespaces, so that there can be no confusion between them.
    I'd say your mistake is trying to set this value into the attribute space yourself rather than using one of the defined interfaces for JSTL to do it - in web.xml, or using the Config class.
    I guess that would make your code
    Config.set(servletContext, Config.FMT_LOCALIZATION_CONTEXT, context); Using their interface for setting this attribute adds the required suffix automatically.
    Cheers,
    evnafets

  • Combing jstl/xml tags with jsf - can't pass parameter

    I'm using the jstl/xml tags to parse portions of an xml document. For some value of an attribute I want to render a search link, many of these links may be rendered on a page and I need to track which one has actually been selected using the id of the generating xml element.
    This is what I've tried, both using h:commandLink and a f:param and t:commandLink (tomahawk) and a t:updateActionListener.
    It doesn't seem to be possible to expose the resolved value of the xpath ="@id" in any way that either the tomahawk or core jsf tags can see.
    <x:when select="$control[@type='SEARCH']">
    <input type="text" id='<x:out select="@id"/>' disabled="true">
    <x:set var="selectedId" select="@id"/>
    <h:commandLink action="#{pack.search}" value="#{msg['actionPack.label.search']}" styleClass="linkNoUnderline">
    <f:param value="${selectedID}" name="selectedID"/>
    </h:commandLink>
    <%--<t:commandLink action="#{pack.search}" value="#{msg['actionPack.label.search']}" styleClass="linkNoUnderline">
    <t:updateActionListener property="#{pack.searchingId}" value="${searchId}"/>
    </t:commandLink>--%>
    </x:when>

    The JSF and JSTL tags don't really play well together.
    Particularly conditional and looping tags.
    My suggestion would be - if you're using JSF, don't use JSTL.
    You are right in that the JSF tags don't bother with the xpath expression.
    Would it be possible to shift the xml logic into an action/bean somewhere, and just present the jsp page with a list of relevant objects?
    If I understand you are trying to determine which link was clicked on a page? In the JSF action "pack.search"?
    What method of iterating are you using? an x:forEachLoop? A datatable?

  • JSTL xml not working

    Hi,
    I'm trying to parse an xml document using JSTL XML libraries. The following is a code snippet from my app:
    <x:parse var="ox" xml="${xml}"/>
         <x:set var="pageItemCount" select='count($ox/osSummary/summaryGroup/summaryItem)'/>
         <x:set var="totalRecords" select="string($ox/osSummary/totalRecords)" scope="request"/>
         <c:set var="pages" value="${totalRecords / qp.pageSize}" scope="request"/>
    <<x:forEach var="n" select="$ox/osSummary/summaryGroup/summaryItem">
    I have verified that the 'xml' variable holds the xml document. However, the <x:parse> function does not seem to parse the XML.
    I am guessing there is something wrong with the JSTL version i'm using. If so, how to i change that? I'm using WAS 6.0
    thanks,
    Vasanth

    Had a maybe similar problem a short while ago. Browse this thread and see if that seems like it. Good luck!
    http://forum.java.sun.com/thread.jspa?threadID=5236722
    John

Maybe you are looking for

  • Set up username & password "admin" are not accepted by the Set Up page

    I hope someone can help. When I finished setting up the router via the cd-set up wizard, I tried getting into the Set Up page via the Internet Explorer. It does not accept the username & password "admin" that is mentionned in the set-up manual. Pleas

  • JS for Find/Change

    I am a novice with JS, but trying to make a couple of enhancements to workflow using scripting. I have managed to figure most things out ok, but usually just need a little kickstart. What I am trying to do is: InDesign CS2 Find a specific sequence of

  • Workflow - Change description "Cancel and keep workitem in inbox"

    Hi, Can you please tell me whether we have a way to change the description of "Cancel and keep workitem in inbox" as "Cancel". Thanks Ashu

  • Bug in julian date

    Must be a bug for year zero? select to_date(1721300,'J') from dual ERROR at line 1: ORA-01841

  • High CPU usage for tcc.exe on Windows XP

    We have the following setup which hosts a JAVA client application: A Netra T12 which is used as a GUI server + SGD server. A 490 acting as another GUI server. Internet Explorer 6 on Windows XP SP1 for the SGD client sessions. When we run clients via