JSTL Question

Hi Guys,
I have an ArrayList of HashMaps that i wish to iterate over using
<c:forEach> tag. How can i do that?
thanks for any help
-navjot

JSTL uses attributes, in fact the pageContext.findAttribute() method. Store your Map in an attribute, for instance:
<%
// scripting
pageContext.setAttribute("myMap", myMap);
%>
<c:forEach items="${myMap}" var="singleItem">
  <c:out value="${singleItem.whatever}"/>
</c:forEach>

Similar Messages

  • That JSTL question...

    ...but I think I already did what I see what is always suggested in the searches I've performed.
    I get this error when I try to load my simple page testform.jsp
    org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
    Here's the complete contents of testform.jsp:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <html><head></head><body>
    ${param.argle == "bargle"}
    <form name="form1" method="post" action="testform.jsp">
         <input type="hidden" name="argle" value="bargle" />
         <input type="submit" name="submit" value="submit" />
    </form></body>
    it should be noted that if I remove the taglib directive the page works fine (the EL returns false before clicking the form button, and returns true if you have clicked the button).
    The directory structure:
    [tomcat's webapps directory]\playground
    ---testform.jsp
    ---\WEB-INF
    ------\lib
    ---------jstl.jar
    ---------standard.jar
    In other words, the jstl and standard jar files are in the WEB-INF\lib directory like I understand they should be. I've looked at the tld files inside the jar. They are using http://java.sun.com/jsp/jstl/core as the uri
    I have tried this exact scenario using both Tomcat 7 and Tomcat 5.5.
    so, the question is,... what am I doing wrong?
    Edited by: 861734 on May 26, 2011 9:28 AM

    I haven't made a web.xml. I was under the belief that to use the core taglib you didn't need it. Am I mistaken?

  • Very simple jstl question

    I for the life of me have not been able to find the answer to this very simple question, googling and looking at various documentation. What is the difference between accessing properties using $ or #? Is there a difference?
    Thanks

    Read on this excellent explanation about the unified EL: http://java.sun.com/products/jsp/reference/techart/unifiedEL.html

  • JSP 2.0 and JSTL question

    Hi,
    I'd just like to ask if anyone could suggest a good site with tutorias about JSP 2.0 and more specific about requesting and manipulating attributes.
    It is easy to do so by using servlets withn something like:
    ArrayList mylist = (ArrayList)request.getAttribute("mylist");
    and use it with an iterator.
    ...but I'd like to learn how I can request and manipulate ArrayLists in JSP using JSTL.
    thanks in advance,
    mike

    All you should need are the <%@ taglib %> and the jar files in your web-inf/lib directory.
    Nothing is required in web.xml for it to work.
    Make sure you are using the JSTL 1.1 taglib URIs though: http://java.sun.com/jsp/jstl/core.
    They look a lot like the old ones, but include /jsp now as well.
    Does the EL evaluate inside a tag? eg <c:out value="${application.servletContextName}"/>
    Couple of things to try
    EL evaluation may be disabled: Put this at the top of your page:
    <%@ page isELIgnored=false %>
    Check your web.xml for something like this (disables EL in pages)
    <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <el-ignored>true</el-ignored>
    </jsp-property-group>
    What version of the DTD are you using for web.xml? According to the JSP spec, if it is less than 2.3, and you haven't specified handling of the EL, it is ignored.
    Relevant bits of the JSP2.0 spec: JSP3.3.2, JSP 1.10.1
    Can you post some code which isn't working?
    Cheers,
    evnafets

  • Basic JSTL question

    Hi, just trying to get to grip with JSTL (although part of me thinks that if the application is to be wholly devloped/mainatined by java programmers they dontr offer much.)
    can someone point me to what Im doing wrong.
    I have a list of dataitems that I can iterate through and print out their attribute
    <c:forEach items="${model.dataitems}" var="dataitem">
         <c:out value="${dataitem.name}"/>
    </c:forEach>But how do I print out the number of dataitems I tried
    <c:out value="${model.dataitems.size()}
    <c:out value="${model.dataitems.size}and neither worked

    That depends on what server/version of JSTL you are using.
    On a JSP2.0 server (Tomcat 5) using JSTL 1.1, then you can use the function library:
    <c:out value="${fn:length(model.dataitems)}"/>In the older JSP1.0 needed for JSP 1.x servers, the function library is not available. If you need the total before the finish of the loop, then you are stuck with either using a scriptlet or writing your own tag (or utility bean) around it.
    If you only need to use the total size of the collection after iteration, you could use the varStatus attribute in the c:forEach loop to get the count:
    <c:set var="count" scope="page" value="${0}"/>
    <c:forEach ... varStatus="status">
      <c:set var="count" value="${status.count}"/>
    </c:forEach>
    Number of Items in the Collection: <c:out value="${count}"/>
    package webutils;
    public class UtilBean {
      private java.util.Collection collection;
      public void setCollection(java.util.Collection c) { collection = c; }
      public int getSizeOfCollection() { return (collection != null) ? collection.size() : 0; }
      <jsp:useBean id="utilBean" class="webutils.UtilBean"/>
      <c:set target="utilBean" property="collection" value="${model.dataitems}"/>
      Number of Items: <c:out value="${utilBean.sizeOfCollection}"/>Not the prettiest of sollutions but that is why they cam up with function libraries in JSTL 1.1...

  • "javax.servlet.jsp.JspException: null" When trying to use JSTL

    Hello,
    I am trying to use some taglibs from Apache but I am getting the following error when trying to access the relevant page:
    org.apache.jasper.JasperException: javax.servlet.jsp.JspException: null
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    org.apache.jasper.JasperException: javax.servlet.jsp.JspException: null
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
         org.apache.jsp.Questions_jsp._jspService(Questions_jsp.java:42)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    javax.servlet.ServletException: javax.servlet.jsp.JspException: null
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.WEB_002dINF.EL_005f2_jsp._jspService(EL_005f2_jsp.java:171)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
         org.apache.jsp.Questions_jsp._jspService(Questions_jsp.java:42)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.lang.reflect.InvocationTargetException
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(Unknown Source)
         org.apache.jsp.WEB_002dINF.EL_005f2_jsp._jspx_meth_c_set_0(EL_005f2_jsp.java:208)
         org.apache.jsp.WEB_002dINF.EL_005f2_jsp._jspService(EL_005f2_jsp.java:113)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
         org.apache.jsp.Questions_jsp._jspService(Questions_jsp.java:42)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)My web.xml file is as follows:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
    version="2.4">
    <display-name>Jsp_Ex09 - JSP Standard Tag Library</display-name>
    <welcome-file-list>
    <welcome-file>welcome.jsp</welcome-file>
    </welcome-file-list>
    <jsp-config>
    <taglib>
    <taglib-uri>/simplequestions</taglib-uri>
    <taglib-location>/WEB-INF/tlds/simplefaq.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
    <taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
    </taglib>
    <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <el-ignored>false</el-ignored>
    <scripting-invalid>true</scripting-invalid>
    </jsp-property-group>
    </jsp-config>
    </web-app>I have the standard and jstl jars in my lib directory and the relevant tlds files int the tlds directory. I am using Tomcat 5.5 and J2EE 5.
    The jsp in question is as follows:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
    <html>
    <head>
    <title>JSTL Q2</title>
    </head>
    <body>
    <h1>JSTL Question 2</h1>
    <h2>How do I use the JSTL?</h2>
    <jsp:useBean id="questions" class="com.apress.faq.Questions"
    scope="page">
    <jsp:setProperty name="questions" property="topic" value="EL"/>
    </jsp:useBean>
    <table border="1">
    <!-- the literal JSTL tag will be in left column of table -->
    <!-- the evaluated JSTL tag will be in right column of table -->
    <tr><th>tag</th><th>result</th></tr>
    <!-- this tag uses c:out to send the value of an EL to the response -->
    <tr><td><c:out value="${'${'}questions.topic}"/></td>
    <td><c:out value="${questions.topic}"/></td>
    </tr>
    <!-- this tag uses c:set to set the property of a JavaBean -->
    <c:set target="${questions}" property="topic" value="JSTL" />
    <tr>
    <td><c:set target="${'${'}questions}" property="topic"
    value="JSTL"/>
    </td>
    <td><c:out value="${questions.topic}"/></td>
    </tr>
    <!-- this tag uses c:if to determine whether to create another row -->
    <c:if test="${questions.topic == 'EL'}">
    <tr><td>This row will not be created</td>
    <td></td>
    </tr>
    </c:if>
    <c:if test="${questions.topic == 'JSTL'}">
    <tr><td>This row was created because the c:if tag result was true</td>
    <td></td>
    </tr>
    </c:if>
    </table>
    <h2>Multiplication table, 1 - 5</h2>
    <!-use the forEach tag to create a table -->
    <table border="1">
    <tr><td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>
    <c:forEach var="i" begin="1" end="5">
    <tr><td><c:out value="${i}"/></td>
    <c:forEach var="j" begin="1" end="5">
    <td><c:out value="${i*j}"/></td>
    </c:forEach>
    </tr>
    </c:forEach>
    </table>
    <h2>Formatting numbers</h2
    <br><fmt:formatNumber value="23.456" type="number" /> results in
    <fmt:formatNumber value="23.456" type="number" />
    <br><fmt:formatNumber type="currency">23.456
    </fmt:formatNumber> results in <fmt:formatNumber
    type="currency">23.456</fmt:formatNumber>
    <br><fmt:formatNumber value=".23456" type="percent"/> results
    in <fmt:formatNumber value=".23456" type="percent"/>
    <br><fmt:formatNumber value=".23456" type="percent"
    minFractionDigits="2"/> results in <fmt:formatNumber
    value=".23456" type="percent" minFractionDigits="2"/>
    </body>
    </html>Can anyone spot the problem?
    Sorry for such a big post!

    ava.lang.reflect.InvocationTargetException
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(Unknown Source)From the stacktrace, it appears to be from a <c:set> tag.
    Invocation target exception would meant that an error was encountered calling the setter.
    That would focus on this part of the code:
    <!-- this tag uses c:set to set the property of a JavaBean -->
    <c:set target="${questions}" property="topic" value="JSTL" />
    <tr>
    <td><c:set target="${'${'}questions}" property="topic"
    value="JSTL"/>
    </td>That nesting of ${ } inside ${} looks dodgy to me. What is it you are trying to achieve?

  • Jsp data display as a result of a button click

    i have a textfield in a jsp along with a SEARCH button. the search button searches the database for the existence of the value entered in the textfield.
    how should i code so that at the click of search button the dbase is searched (for the entered value in textfield).
    the dbase should be searchedonly after the click of search button.
    i wud also like to display the searched value as a table data next to the button. how shud i code it. i coded search logic using a function which is in a javascript. but the function is executing before the press of the search button.
    i'm new to JSPs. please help.. thanks.

    It's covered by every decent JSP/Servlet book/tutorial. With other words, this is too trivial and it proves that you really know nothing about it at all. I then highly recommend to take time first to go through a decent book/tutorial. This forum is to help others with technical coding problems, not to spoonfeed others who cannot write code.
    To start with HTML: [http://www.w3schools.com/html/].
    A nice HTML book: [http://www.amazon.com/HTML-Dummies-Ed-Tittel/dp/076450214X].
    To start with JSP/Servlet: [http://java.sun.com/javaee/5/docs/tutorial/doc/ (part II chapters 1-8)].
    A nice JSP/Servlet book: [http://www.amazon.com/Head-First-Servlets-JSP-Certified/dp/0596516681].
    It boils down to having a HTML <form>, <input type="text"> and <input type="submit"> in the JSP page and havinig a Servlet with necessary code in the doPost() method which obtains the request parameter, queries the database, stores the result in the request scope and forwards the request to a JSP for display -which on its turn uses JSTL c:forEach to iterate over the list of results.
    Good luck. If you ever have a technical JSP/JSTL question/problem, you're welcome to ask here.

  • Jsp:plugin jre version

    I am using jsp:plugin tag to put my applet in jsp. The default jre verion of the jsp:plugin is 1.2. I want users to use jre 1.4. How can I wite the attribute for the tag?
    <jsp:plugin
    type="applet"
    code="mypackage.MyApplet"
    //any other attribute I should use?
    jreversion = ???
    iepluginurl =???>
    Thanks,
    autogoor

    You may want to repost your strut JSTL question at J2EE forum.

  • Jsp:plugin jre

    Hello
    On the my system I have JAVA_HOME set to 1.4._10, in the browser NS, I have1.5_06, however the 1.4_10 plugin. The code below when processed by Tomcat 5.5.12 complains about a jre mismatch. How can I make the plugin configuration accept anything higher than 1.4.1? Thank you.
    <jsp lugin type="applet" code="showParms.class"
    codebase="https://localhost:9443/ssl-ext/applets" jreversion="1.4.1">
    <jsp arams>
    <jsp aram name="param1" value=""/>
    <jsp aram name="param2" value=""/>
    <jsp aram name="param3" value=""/>
    <jsp aram name="param4" value=""/>
    <jsp aram name="param5" value=""/>
    </jsp arams>
    <jsp:fallback>
    Sorry we are unable to start the Java plugin. You must first dn stuff>
    </jsp:fallback>
    </jsp lugin>

    You may want to repost your strut JSTL question at J2EE forum.

  • C_rt:forEach help

    ok. Here's some code. It won't work. I have fmt.tld and c-rt.tld in my tlds folder, included is the jsp page:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c_rt" %>
    <%@ taglib uri="http://java.sun.com/jstl/format" prefix="fmt" %>
    <html>
    <head>
    <title>JSTL Q2</title>
    </head>
    <body>
    <h1>JSTL Question 2</h1>
    <h2>How do I use JSTL?</h2>
    <p>Multiplication table, 1-5</p>
    <!-- Use the forEach tag to create a table -->
    <table border="1">
    <tr>
    <td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td>
    </tr>
    <c_rt:forEach var="i" begin="1" end="5">
    <tr>
    <td><c_rt:out value="${i}"/></td>
    <c_rt:forEach var="j" begin="1" end="5">
    <td><c_rt:out value="${i*j}"/></td>
    </c_rt:forEach>
    </tr>
    </c_rt:forEach>
    </table>
    </body>
    </html>
    and the appropriate parts of web.xml
    <taglib>
    <taglib-uri>http://java.sun.com/jstl/core_rt</taglib-uri>
    <taglib-location>/WEB-INF/tlds/c-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jstl/format</taglib-uri>
    <taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
    </taglib>
    any ideas would be much appreciated.....

    You need to use the core tags, not the core_rt tags, if you are intending to use JSP EL.
    That is:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <table border="1">
    <tr>
    <td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td>
    </tr>
    <c:forEach var="i" begin="1" end="5">
    <tr>
    <td><c:out value="${i}"/></td>
    <c:forEach var="j" begin="1" end="5">
    <td><c:out value="${i*j}"/></td>
    </c:forEach>
    </tr>
    </c:forEach>
    </table>
    </body>
    </html>Cheers, Neil

  • Question regarding JSTL and function calls

    Hello
    I'm quite new to JSTL and I'm having a problem accessing a function when I want to pass argument to that function.
    Im using MVC where my M (model.jsp) can be accest from my V (view.jsp) by doing ${model.(parameter/some function) }
    in my M I have a couple of getMethods() (example: getThisInfo() ) and som control methods like "isSomethingValid(arg1)"
    my question is lets say I want to access my "isSomethingValid(arg1)" and arg1 should be the value of "getThisInfo()" I thought I could do like
    ${model.somethingValid($model.thisInfo)} but it isnt working I get:
    "Unable to parse EL function ${model.somethingValid(model.thisInfo)}"
    I know that the syntax above is a mix of scriptlet and JSTL but I dont know how to or if its even possible to achieve this?
    Thanks for helping me!
    Best Regards/DS

    By default, EL can only access getters and setters on objects.
    It can not execute general methods on an object.
    You can define function libraries that call static methods
    You have to write the method as static, and then declare it in a tld.
    public boolean checkValid(Model m, Info i){ ...}
    and then you could invoke it something like
    <%@ taglib uri="myfunctionstaglib" prefix="myfunctions" %>
    ${myfunctions:checkValid(model, model.thisInfo)}

  • Newbie question: JSP x JSTL (Will JSTL kill JSP?)

    Hi,
    I'm newbie in java development and know I'm learning about jsp and jstl.
    I'm reading some articles about jstl, but my doubt remains...
    Was jstl create to kill jsp in apresentation layer?
    Please, if possible, show me an example that I really need use jsp instead of jstl?
    What kind of things can't I do with jstl?
    Thanks a lot

    Ranieri wrote:
    I'm sorry, my question wasn't very clear.
    When I said JSP, I wanted say Scriptlet...
    My central point is that Scriptlet is very confortable for me at the moment...
    So, I don't see a motive to change:
    <% if (1 == 2) }....
    to
    <c:if test="1 eq 2">...Lots of motive to change.
    Now... you can say that jstl is more easy, Or you can say that JSTL is easier.
    but if a big number of people start to use it, it will increase and will turn another programming language...It sounds like you think this is a new thing. JSTL has been around for a very long time. 2001 vintage. It's already here, dude.
    Besides, it's not a programming language per se. There will be other tag libraries, but those are custom. JSTL as written hasn't changed in years. The standard won't expand.
    So, why create another programming language if we have Scriptlet to do the same?Like I said before, scriptlets were the mistake. They're unreadable, ugly, and encourage putting logic in JSPs. Very bad, indeed.
    %

  • J2EE, JSTL and JSF questions

    I am trying to learn J2EE/JSTL/JSF and have quite a few general questions. Any help on any of these is appreciated.
    1) Is there a way, just by using J2EE/Java to "manipulate" an XML file. Not just parse and read it's data but actually add nodes to the file?
    2) I've been reading quite a bit on JSTL and JSF recently. Is JSF supposed to be an alternative to Struts and JSTL an alternative to scriptlet coding?
    3) I am also working on creating a message board but throwing around a couple of ways to implement it. Either (a) using a database to store posts and a JSP interface or (b) using an XML document to store postings. Which of these two seem best or is there a better option?
    4) Is there an easy way to call Php from a Java program? I need to invoke a php program when a user clicks on a link on a JSP page I have.

    1) The SDK provides JAXP (Java API for XML Processing) in javax.xml package.
    2) I wouldn't call it 'alternative'.
    3) Your choice. I'd to use a RDBMS. Less overhead, better suited, (much) more functions and better performance.
    4) If that program is available on the web, then just invoke a HTTP request. If not, I'd rather to rewrite it to Java.

  • Genereting JSTL tags with an XSLT transformation question

    Hi there!
    I have some XML datas to display in a jsp file.
    XML content is of this type:
    <message>
    <title>A message</title>
    </message>
    The most elegent way to present them is to transform XML via xslt into xhtml.
    (that way I can externally change with ease the message formatting output without changing the jsp)
    For that, I use the cool tag
    <x:transform>
    on each xml file i want to display (with x:foreEach)
    The output produced for each xml file is:
    <div class="message">
    <h2>A message</h2>
    </div>
    My problem is now that I want to include custom tags in the generated content!
    For exemple:
    <div class="message">
    <h2>A message<c:out ...></h2>
    </div>
    My question is:
    how can I make that xslt generated tag to be executed???
    Since it is the product of an xslt transformation ,I suppose it won't be executed at all...
    Advices greatly appreciated! :)

    I'm not sure I understand what you mean when you say "how can I make that xslt generated tag to be executed???"
    You've got your XML input and the XSL-T stylesheet that will transform the XML input into an XHTML stream containing JSTL tags.
    I'm assuming that you're going to ask a servlet to pass the XML input to the XSL transformer and get the XHTML output stream. Once you have that, the servlet will write the XHTML to the HTTP response output stream, where it'll be rendered by the browser.
    I think the key is to make sure that you tell the browser that response type is a JSP (that's the only document type in which it makes sense to put JSTL tags). When the browser gets that JSP, it'll treat it like any other: generate .java code, compile that to a .class file, and then render.
    I'm not sure about efficiency, but it sure is an elegant solution. - MOD

  • Question | Using JSTL to Display elements of an ArrayList of HashMaps

    Hi All,
    I would like some advice on the following code snippet which is a representation of my real code. Please see below for the code snippet and the specific questions I have.
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%
    // This Object is an ArrayList of HashMaps
    MyClassDataBean myDb =  (MyClassDataBean)session.getAttribute("testDataBean");
    // Adding myDb to the pageContext so that EL can be used to render components in this Object
    pageContext.setAttribute("myDb",myDb);
    pageContext.setAttribute("column1",MyConstants.COLUMN1);
    pageContext.setAttribute("column2",MyConstants.COLUMN2);
    %>
    <html>
    <head></head>
    <body>
         <c:choose>
          <c:when test="${myDb != null}" >
             <c:forEach var="hashMapAsRow" items="${myDb}" varStatus="lineInfo">
              <tr>
                  <td><c:out value="${hashMapAsRow[column1]}" /></td>
               <td><c:out value="${hashMapAsRow[column2]}" /></td>
               </tr>
         </c:forEach>
         </c:when>
         <c:otherwise>
         <tr><td colspan="100%">No Data Exists</td></tr>
         </c:otherwise>
       </c:choose>
    </body>
    </html>Question: Is there an alternative to accessing elements using the core tag library in this Object without using pageContext.setAttribute() ? If not, would the c_rt library be better to use in this scenario? If so, could someone give me an example of the right way to use it based on the above example?
    Thanks,
    Joe

    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <c:set var="myDb"  value="${sessionScope.testDataBean}" />
    <html>
    <head></head>
    <body>
          <c:choose>
           <c:when test="${myDb != null}" >
              <c:forEach var="hashMapAsRow" items="${myDb}" varStatus="lineInfo">
               <tr>
                   <td><c:out value="${hashMapAsRow['column1']}" /></td>
                 <td><c:out value="${hashMapAsRow['column2']}" /></td>
                </tr>
         </c:forEach>
          </c:when>
          <c:otherwise>
         <tr><td colspan="100%">No Data Exists</td></tr>
          </c:otherwise>
        </c:choose>
    </body>
    </html> or the one below
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <html>
    <head></head>
    <body>
          <c:choose>
           <c:when test="${sessionScope.testDataBean != null}" >
              <c:forEach var="hashMapAsRow" items="${sessionScope.testDataBean}" varStatus="lineInfo">
               <tr>
                   <td><c:out value="${hashMapAsRow['column1']}" /></td>
                 <td><c:out value="${hashMapAsRow['column2']}" /></td>
                </tr>
         </c:forEach>
          </c:when>
          <c:otherwise>
         <tr><td colspan="100%">No Data Exists</td></tr>
          </c:otherwise>
        </c:choose>
    </body>
    </html> is this the one which you are looking for ??
    REGARDS,
    RaHuL

Maybe you are looking for