JSP XML question

I'm trying to write a jsp page that goes to the following page and returns the XML it generates, parses it, then prints out to the screen what it is.
maybe I'm over thinking this but it's driving me nuts
thanks in advance
Pete
here's my code
<%@ page import = "java.io.*, java.util.*, java.lang.*" %>
<%@ page import = "oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@ page import = "oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@ page import = "oracle.portal.provider.v2.url.*" %>
<%@ page import = "org.campuseai.ErrorHandler" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.lang.String" %>
<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setHeader("Content-type", "text/html");
response.setHeader("Expires", "Thu, 29 Oct 2000 17:04:19 GMT");
PortletRenderRequest pr = (PortletRenderRequest) request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);     
String hslURL = UrlUtils.absoluteLink(pr, "/");
%>
<%
     String level5 = (hslURL + "severe.png");
     String level4 = (hslURL + "high.png");
     String level3 = (hslURL + "elevated.png");
     String level2 = (hslURL + "guarded.png");
     String level1 = (hslURL + "low.png");
     String hlsURL = "http://www.dhs.gov/dhspublic/getAdvisoryCondition";
     String inputLine;
     String hlsTest5 = "SEVER";
     String hlsTest4 = "HIGH";
     String hlsTest3 = "ELEVATED";
     String hlsTest2 = "GUARDED";
     String hlsTest1 = "LOW";
URL gov = new URL(hlsURL);
          try {
               gov.openConnection();
          catch (MalformedURLException e) {    
               System.out.println(e.getMessage());
     BufferedReader in = new BufferedReader(new InputStreamReader(gov.openStream()));
          while ((inputLine =in.readLine()) != null) {
               out.println(inputLine);
               if (inputLine.equals(hlsTest5))
                         out.println("SEVER");
               if (inputLine.equals(hlsTest4))
                         out.println("HIGH");
               if (inputLine.equals(hlsTest3))
                         out.println("ELEVATED");
               if (inputLine.equals(hlsTest2))
                         out.println("GUARDED");
               if (inputLine.equals(hlsTest1))
                         out.println("LOW");
               in.close();
%>

I did is 9 lines of code in php youo 'd think it would be easy to convert!
Pete
just in case anybody wanted the php code:
<?php
$saURL = "http://www.dhs.gov/dhspublic/getAdvisoryCondition";
$myFile= (file($saURL));
     $text = str_replace("<THREAT_ADVISORY CONDITION=\"","",$myFile[1]);
     $myFile = str_replace("\" />","",$text);
$myFile = trim($myFile).".png";
$myFile = strtolower($myFile);
echo "<center><a href=\"http://www.dhs.gov/\" target=\"blank\"><img src=\"level/" . $myFile . "\" vspace=5 border=0></a></center>";
?>

Similar Messages

  • JSP, XML, XSLT: applying XSL on JSP-generated XML doc

    Hello,
    I am currently trying to figure out how to do the following:
    let's consider (that's not entirely hypothetical :) ) a web application working with JSP (on apache/tomcat 3.1) and oracle BC4J Application modules.
    The JSPs call oracle webbeans to perform updates and retrieve data from an 8.1.6 database.
    Now I'm thinking of moving to a combination of JSP, XML and XSL, which (hopefully) would allow to customize the application depending on the user's browser, language etc...(that's the point isn't it?)
    It doesn't seem to be a problem to produce XML from a jsp, send it directly to the client browser, which in turn goes to look for the proper XSL file and does all the transformation stuff.
    However this only works with I.E 5 for the moment right? and most website need to support various kinds of browsers...
    The need is:
    * When a non XML-capable browser is detected, apply the proper XSL(s) on the server side before sending the result back, in html/wml/whatever...
    * For XML-capable browsers, produce raw XML, maybe apply some XSL(s), and eventually send the result to the browser which handles the rest of the XSL stuff itself.
    Therefore, I'd like to:
    - Have the jsp produce the raw xml data (maybe adding extra tags, to indicate the browser and/or the language that the jsp engine has detected).
    - Pass the output to a first XSLT engine which would take care of the language stuff
    - Feed the result into a second XSLT engine to handle browser specificities for instance...
    - Send the final output to the client browser.
    Now, there are 2 problems:
    * 1/ I have seen various engines capable of chaining XSL transforms, and it is easy to produce XML from a jsp, but I don't know how to feed a jsp's output into an XML engine. is that possible? how?
    * 2/ I'm a bit concerned about the cost of applying three (or more) process stages, does anyone have insight on the performance issues this could raise?
    bonus question ;) : is there a simpler approach?
    Thanks a lot in advance, Remi
    null

    Hello,
    I am currently trying to figure out how to do the following:
    let's consider (that's not entirely hypothetical :) ) a web application working with JSP (on apache/tomcat 3.1) and oracle BC4J Application modules.
    The JSPs call oracle webbeans to perform updates and retrieve data from an 8.1.6 database.
    Now I'm thinking of moving to a combination of JSP, XML and XSL, which (hopefully) would allow to customize the application depending on the user's browser, language etc...(that's the point isn't it?)
    It doesn't seem to be a problem to produce XML from a jsp, send it directly to the client browser, which in turn goes to look for the proper XSL file and does all the transformation stuff.
    However this only works with I.E 5 for the moment right? and most website need to support various kinds of browsers...
    The need is:
    * When a non XML-capable browser is detected, apply the proper XSL(s) on the server side before sending the result back, in html/wml/whatever...
    * For XML-capable browsers, produce raw XML, maybe apply some XSL(s), and eventually send the result to the browser which handles the rest of the XSL stuff itself.
    Therefore, I'd like to:
    - Have the jsp produce the raw xml data (maybe adding extra tags, to indicate the browser and/or the language that the jsp engine has detected).
    - Pass the output to a first XSLT engine which would take care of the language stuff
    - Feed the result into a second XSLT engine to handle browser specificities for instance...
    - Send the final output to the client browser.
    Now, there are 2 problems:
    * 1/ I have seen various engines capable of chaining XSL transforms, and it is easy to produce XML from a jsp, but I don't know how to feed a jsp's output into an XML engine. is that possible? how?
    * 2/ I'm a bit concerned about the cost of applying three (or more) process stages, does anyone have insight on the performance issues this could raise?
    bonus question ;) : is there a simpler approach?
    Thanks a lot in advance, Remi
    null

  • HELP: JSP + XML + XSLT = HTML?

    Hello, all.
    I am trying out Weblogic 6 and I am trying to get the JSP + XML + XSLT =>
    HTML chain working.
    I am coming from using Orion and SAXON.. and in that situation I had a JSP
    that contained XML tags... they were filled in at runtime and then using
    Servlet-Chaining was passed along to the SAXON XSLT Processer. SAXON checked
    for the inline XSL specified and then used that to transform the document
    into HTML.
    It worked well, but there were some other features missing/not documented
    that we now need.
    With Weblogic I am trying to use the XSLT Tag Library that comes with the
    distribution, but it seems to be very finicky. I followed the directions and
    I got it to do a sort of roundabout transformation. But it doesn't seem to
    work quite right.
    The best I can get is the following:
    I have an 'xslt' directory url-pattern-mapped to xslt.jsp (as instructed)...
    but can't figure out how to specify the xsl file on-the-fly... that is, if I
    don't hard-code the XSL file in the x:xslt element in the xslt.jsp it
    complains about some XML file not having a root element.
    Ideal situation:
    1. I have a JSP that includes XML elements.
    2. It is filled from a database at runtime and specifys (using a PI) what
    XSL stylesheet it is to be processed with.
    3. Somehow (fingers crossed) the XML is processed and transformed into HTML
    by the appropriate XSL file.
    I think I am mostly stuck moving between steps 2 and 3.
    Can anyone give me some hints? Are there some Weblogic specific
    elements/tags that I have to include in the XML file that Weblogic will
    catch and re-direct to the XSL Parser?
    Please, anyone, if you have some information, I would much appreciate it.
    Dylan Parker
    PS - I apologize for the cross-post, I hope it doesn't cause too much
    traffic.

    Craig,
    I've since discovered how to do it with the WL Taglibrary... and have
    moved on =)
    It has to do with the EXTREMELY BADLY documented x:xml tag that can
    appear within the x:xslt tag body...
    So the WL Tag Library allows something like the following.
    (Please note, angled brackets are omitted in this post to prevent html
    parsing)
    [x:xslt stylesheet="sheet.xsl"]
    [x:xml]
    Here is the XML to run the sheet on.
    This should have all relevant XML syntax: the PIs, the doctype,
    root elements etc...
    [x:xml]
    [x:xslt]
    And that DOES work. But not very well. WL, a little prematurely
    incorporated versions 1.2 of Xerces and Xalan in their product -- and
    these versions have some irritating bugs.
    Also -- There tag library doesn't copy the source XML across as UTF-8
    .. so a lot of the Japanese I have embedded there (from a DB) gets
    mangled somewhere in their code...
    AND -- If you hammer a little bit on an JSP/XML that uses the WL Tag
    Library (eg clicking refresh lots of times in IE)... I get huge
    amounts of irritating exceptions appearing in the log files.
    NullPointerExceptions
    XSL Parsing Exceptions
    XML Parsing Exceptions
    but completely unpredictably...
    In my eyes.. the WL XML/XSL Tag Library using the incorporated and
    untouchable Xalan and Xerces (v1.2) is virtually unusable.
    What a pain.
    BUT! Apache offers a similar OPEN SOURCE XSL Tag Library available
    here:
    http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
    And it uses the standard, non-weblogic-incorporated, Xerces and Xalan
    (which means you can provide whatever version you want).. and it works
    impressively well.
    It has almost identical performance as the WL Taglib, and without all
    of the bizarre exceptions being thrown.
    And it does proper passing of the character encoding type!
    If only the taglib did caching though =(
    The performance hit over pure JSP is huge. Almost two orders of
    magnitude. On my desktop box I can get around 500Requests/Sec if I am
    returning HTML direct from a JSP... while if I produce XML that gets
    processed by XSL into HTML the Requests/Sec drops to 5!!!!
    Caching. Caching. And more Caching. A lot of DiskIO is going on with
    the XML/XSL/XHTML chain of events.
    I hope this helps!
    I'd be curious as to what you find out as well.
    Dylan Parker
    On 5 Mar 2001 07:20:00 -0800, "Craig Macha"
    <[email protected]> wrote:
    >
    Yep, I feel Dylan's pain.
    I am trying to accomplish the same thing. A JSP page generating
    dynamic XML content and then utilizing an XSLT stylesheet to transform
    all the content into XHTML.
    Does anyone have some examples that show exactly how to accomplish
    this? Can I do this with WLS and the XML taglib that comes with
    it? Or do I have to move on to something like Cocoon to get this
    capability?
    Any insight would be greatly appreciated.
    Thanks,
    Craig Macha
    "Dylan Parker" <[email protected]> wrote:
    Hello, all.
    I am trying out Weblogic 6 and I am trying to get the
    JSP + XML + XSLT =>
    HTML chain working.
    I am coming from using Orion and SAXON.. and in that situation
    I had a JSP
    that contained XML tags... they were filled in at runtime
    and then using
    Servlet-Chaining was passed along to the SAXON XSLT Processer.
    SAXON checked
    for the inline XSL specified and then used that to transform
    the document
    into HTML.
    It worked well, but there were some other features missing/not
    documented
    that we now need.
    With Weblogic I am trying to use the XSLT Tag Library
    that comes with the
    distribution, but it seems to be very finicky. I followed
    the directions and
    I got it to do a sort of roundabout transformation. But
    it doesn't seem to
    work quite right.
    The best I can get is the following:
    I have an 'xslt' directory url-pattern-mapped to xslt.jsp
    (as instructed)...
    but can't figure out how to specify the xsl file on-the-fly...
    that is, if I
    don't hard-code the XSL file in the x:xslt element in
    the xslt.jsp it
    complains about some XML file not having a root element.
    Ideal situation:
    1. I have a JSP that includes XML elements.
    2. It is filled from a database at runtime and specifys
    (using a PI) what
    XSL stylesheet it is to be processed with.
    3. Somehow (fingers crossed) the XML is processed and
    transformed into HTML
    by the appropriate XSL file.
    I think I am mostly stuck moving between steps 2 and 3.
    Can anyone give me some hints? Are there some Weblogic
    specific
    elements/tags that I have to include in the XML file that
    Weblogic will
    catch and re-direct to the XSL Parser?
    Please, anyone, if you have some information, I would
    much appreciate it.
    Dylan Parker
    PS - I apologize for the cross-post, I hope it doesn't
    cause too much
    traffic.

  • What changes i should made in web.xml for using jsp/xml using weblogic

    Hi all,
    I just know some changes has to made in web.xml or weblogic.xml if i have to use weblogic for jsp/xml.
    Pls. anybody post the steps to intereaction with xml using weblogic.
    I am using jdk1.4

    The problem is solved.
    The information is given at
    http://e-docs.bea.com/wls/docs61/webapp/webappdeployment.html

  • Where to ask XML-questions

    Hello,
    when I have a question about XML, where do I ask?
    XML DB issues related to XML DB
    XML  space for the following subspaces
    General XML  Discussion of the general XML language, standards (XSLT, XQuery, XMLSchema, etc.) and application management issues, suggestions and tips.
    PL/SQL XML Programming  PL/SQL programming using XDK and related management issues inside Oracle database server. Any question for XML DB functionality, please post your question in Products -> Database-> XML DB.
    XQuery Discussion of Oracle XQuery Technology Preview, W3C XQuery specifications, and JSR 225: XQuery API for Java (XQJ) issues
    I think I now have an idea (not that I'm sure about it) where my question will fit best. Now, because there is an explanation of the scope of the space, I don't remember something like this in the old forum. Nevertheless it might be confusing for a new member or one that lacks a certain knowledge about the subtleties:
    One step forward everyone who understands the explanation for the PL/SQL XML Programming space!
    When I have a question about XQuery, how can I decide whether XQuery is correct or General XML?
    Which questions qualify for XML DB and not for any of the others.
    We all know that many users are not able to see that SQL questions don't belong into the SQL Developer space, how can we expect that they will find the "correct" forum for XML questions? In the end they will end up in the SQL and PL/SQL space anyhow :-)
    Regards
    Marcus

    My $0.02.
    As I recall, the explanation for each forum was at the entry level for each forum and not displayed within the forum itself.
    The PL/SQL XML Programming space refers to the Oracle XML Developer Kit.  It is maintained by a different team than the XMLDB so the need for a separate space for it makes sense.  That said, what it covers is also part General XML and XQuery if you dig into what you can do in the XDK.
    Some questions that would qualify for the XML DB space.
    Anything related to schema registration or downstream of schema registration.  Such as querying/performance/indexes/etc.
    Issues parsing XML via using XMLTable (or XQuery, such as the new XQuery update added in 11.2.0.3) (Yes that can conflict)
    Storage of data in XMLType columns
    I to have always been a bit unclear on the exact division between groups in this XML space.  I see the XQuery space as being a subset of the General XML space.  I watch all three forums, as they are normally low volume and you never know where a question will pop up.  As you have seen, questions often end up in the wrong forum and often General XML gets an influx of questions that should go into the Business Intelligence space as well.  There is no good way right now to start a generic post and let the system suggest forums that the post could go into, based on content or software involved.  That would be a nice touch for the future.

  • XMLTYPE variable converting to XML (Question)

    Friends,
    I am stuck on an error and cannot find a way out. Please help. I know it's a long question but a very simple answer to many smart people here. I am just lost and need your help. (I am new to SOA so bear with me)
    I have a BPEL process which invokes a PL/SQL API which returns the XMLTYPE output which has the XML data. In order to convert the XMLTYPE to normal XML I do following :-
    - I added a Java embed activity in BPEL with following code (Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML is the XMLTYPE)
    (responsePayoad is string variable)
    try{                                                           
    Node node = (Node)getVariableData("Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML");
    Node childNode = (Node) node.getFirstChild();
    StringWriter writer = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(childNode), new StreamResult(writer));
    String xml = writer.toString();
    String nsXML = xml.replaceFirst("<FetchCustomerInfoResponse","<FetchCustomerInfoResponse xmlns=\"http://xmlns.djoglobal.com/OrderTracking/CustomerInfo\" ");
    setVariableData("responsePayload",nsXML);
    addAuditTrailEntry("XML with Namespace: " + nsXML);
    } catch(Exception e){                            
    addAuditTrailEntry(e);
    System.out.println("Namespace injection failed due to : " + e);
    After above I have ASSIGN activity where I use parsexml function on the "responsePayload" variable to assign to a variable of type element which refers to following xsd. This is where I get an "internal xpath error" during runtime which I cannot resolve.
    XSD of the element variable refering to "FetchCustomerInfoResponse" element
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.org"
    targetNamespace="http://xmlns.djoglobal.com/OrderTracking/DJOFetchCustomerOrderInfo"
    elementFormDefault="qualified">
    <xsd:element name="FetchCustomerInfoResponse">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDERS">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDER" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:attribute name="ordered_date" type="xsd:string"/>
    <xsd:attribute name="cust_po_number" type="xsd:string"/>
    <xsd:attribute name="order_number" type="xsd:integer"/>
    <xsd:attribute name="header_id" type="xsd:integer"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    XML returned in the XMLTYPE from the PL/SQL API :-
    <Invoke_new_get_customer_order_info_OutputVariable><part name="OutputParameters" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/XXDJO_ONT_ORDER_TRACKING_WS/GET_CUSTOMER_ORDER_INFO_XML/"><X_CUSTOMER_ORDER_INFO_XML>
    <FetchCustomerInfoResponse xmlns="">
    <DJO_ONT_ACCOUNT_ORDERS>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="24-APR-12" cust_po_number="PO1" order_number="123456" header_id="7777777"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="19-APR-12" cust_po_number="PO2" order_number="4545454" header_id="888888"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="09-APR-12" cust_po_number="PO3" order_number="56565656" header_id="999999"/>
    </FetchCustomerInfoResponse>
    </X_CUSTOMER_ORDER_INFO_XML>
    </OutputParameters></part></Invoke_new_get_customer_order_info_OutputVariable></messages>
    Any help is greatly appreciated as this is driving me nuts.
    Thanks

    Few modifications,
    1. Initialize your int count to 0, int count=0;
    2. Write count++; as the first statement in your for loop. 3. Remove count++; at the bottom.
    4. Add a hidden field to your form (after submit button, but before your </form> tag)
    <input type="hidden" name="qCount" value="<%=count%>">
    Now use this code,
    writeXML.jsp
    <%
    int qCount = Integer.parseInt(request.getParameter("qCount"));
    String home ="C:\\Tomcat\\FYProject\\lib\\";
    String filename = request.getParameter("file");
    String extension = ".xml";
    String filePath = home + filename + extension;
    BufferedWriter bw = new BufferedWriter(new FileWriter(filePath,true));
    bw.write("<mc_QuestionType>");
    bw.newLine();
    for(int count=0;count<qCount;count++) {
         String Tquestion = request.getParameter("questionText"+count);
         String answer1 = request.getParameter("choice_1"+count);
         String answer2 = request.getParameter("choice_2"+count);
         String answer3 = request.getParameter("choice_3"+count);
         String answer4 = request.getParameter("choice_4"+count);
         String Canswer = request.getParameter("cAnswer"+count);
         bw.write(" <questionText>" Tquestion "</questionText>");
         bw.newLine();
         bw.write(" <choice>" answer1 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer2 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer3 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer4 "</choice><br>");
         bw.newLine();
         bw.newLine();
         bw.write(" <answer>" Canswer "</answer>");
         bw.newLine();
         bw.write("</mc_QuestionType>");
         bw.close();
    %>Hope this works.
    Sudha

  • JSP XML file parsing XSLT using Xalan

    Hi all
    I have created an XML file "view_campaign.xml" using JSP as shown in a code below and i wanna know how i should proceed to parse the XML file and so i can display this XML as the XSLT file i created.
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%
    // Identify a carriage return character for each output line
    int iLf = 10;
    char cLf = (char)iLf;
    // Create a new empty binary file, which will content XML output
    File outputFile = new File("C:\\WebContent\\view_campaigns.xml");
    //outputFile.createNewFile();
    FileWriter outfile = new FileWriter(outputFile);
    // the header for XML file
    outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
    try {
         // Define connection string and make a connection to database
         //DriverManager.registerDriver (new org.apache.derby.jdbc.ClientDriver());
         Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
         Statement stat = conn.createStatement();
         // Create a recordset
         ResultSet rset = stat.executeQuery("Select * From campagn");
         // Expecting at least one record
         if( !rset.next() ) {
              throw new IllegalArgumentException("No data found for the campaigns table");
         outfile.write("<campaigns>"+cLf);
         outfile.write("<campaign>"+cLf);
         outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
         outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
         outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
         outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
         outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
         outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
         outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
         outfile.write("</campaign>"+cLf);
         // Parse our recordset
    // Parse our recordset
         while(rset.next()) {
              outfile.write("<campaign>"+cLf);
              outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
              outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
              outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
              outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
              outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
              outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
              outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
              outfile.write("</campaign>"+cLf);
         outfile.write("</campaigns>"+cLf);
         // Everything must be closed
         rset.close();
         stat.close();
         conn.close();
         outfile.close();
    catch( Exception er ) {
    %>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    this is my .XSL file
    <?xml version="1.0" encoding="iso-8859-1" ?>
    - <!--  DWXMLSource="view_campaigns.xml"
      -->
      <!DOCTYPE xsl:stylesheet (View Source for full doctype...)>
    - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    - <xsl:template match="/">
    - <html xmlns="http://www.w3.org/1999/xhtml">
    - <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Gestion des campagnes</title>
      </head>
    - <body>
      Gestion des campagnes
    - <table border="1">
    - <tr bgcolor="#9acd32">
      <th align="left">Code</th>
      <th align="left">Nom</th>
      <th align="left">Type</th>
      <th align="left">Client</th>
      <th align="left">Nombre de positions</th>
      <th align="left">Date d'ouverture</th>
      <th align="left">Date de cl�ture</th>
      </tr>
    - <xsl:for-each select="campaigns/campaign">
    - <tr>
    - <td>
      <xsl:value-of select="campaign_id" />
      </td>
    - <td>
      <xsl:value-of select="campaign_name" />
      </td>
    - <td>
      <xsl:value-of select="campaign_type" />
      </td>
    - <td>
      <xsl:value-of select="client" />
      </td>
    - <td>
      <xsl:value-of select="positions" />
      </td>
    - <td>
      <xsl:value-of select="begin" />
      </td>
    - <td>
      <xsl:value-of select="close" />
      </td>
      </tr>
      </xsl:for-each>
      </table>
      </body>
      </html>
      </xsl:template>
      </xsl:stylesheet>I would be greatful that u answer my question what i should do have any exemple case study.

    Hi,
    Try this code
    JspWriter out = pageContext.getOut(); // Get JSP output writter
          javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); //Instantiate a TransformerFactory.           
          String realPath = "c:/applyXsl.xsl";
          java.io.File file = new java.io.File(realPath); // crearte a file object for given XSL.
          // Use the TransformerFactory to process the stylesheet Source and  generate a Transformer.           
          javax.xml.transform.Transformer transformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource(file));
          java.io.StringReader inputStream = new java.io.StringReader("c:/xmlFile.xml"); // create an input stream for given XML doc
          java.io.ByteArrayOutputStream obj = new java.io.ByteArrayOutputStream(); // Create an output stream for XSL applied XML doc.
          // 3. Use the Transformer to transform an XML Source and send the output to a Result object.
          transformer.transform(new javax.xml.transform.stream.StreamSource(inputStream), new javax.xml.transform.stream.StreamResult(obj));
          String outputString = obj.toString(); // get the XSL applied applied XML document for print
          out.println(outputString); // print the XSL applied XML in to JSP.
    however you need xercesImpl.jar  and xml-apis.jar files  to run this program.
    Regards,
    Ananth.P

  • Web Based Messageboard (JSP, XML, XSLT) - Just Looking For Advice Please!

    I have a general question - I am not looking for any code, just some advice if possible. I am studying on a Masters course and I have been given an assignment to do which I am having difficult getting started. I have worked a lot with Java up until now, however this is the first time I have had to JSP on my course.
    My current assignment is that I am required to create a simple web based message board, using JSP and XML, which allows users to post messages to the board, and also to reply to messages. The content of the message board is stored in an XML file, and there is no database involved. The message data needs to be formatted for viewing in a browser using XSL transformations.
    I am stuck as to how to go about starting the project, and this is all I am asking for advice in. I have created the basic XML file which has some preliminary data stored within it, and I have created an XSL stylesheet to transform this data, however I am stuck with the JSP. Do I need to create a seperate JSP page for each page of the website? How does this link in with the XSLT?
    I would welcome and really appreciate any advice, but I stress that I am not looking for anyone to give me any code or anything like that.
    Thanks.

    You can use XSLT to convert XML to HTML. Then include this HTML in your JSP. Further on you've a plain HTML form with an input field for a message which you submit to a servlet. In the servlet validate/convert/whatever this message and add it to the XML file and then forward/redirect the request back to the JSP.

  • Servlet + JSP + SQL question

    I have a servlet that is executing a few queries against a database. I am fowarding the results to a jsp page to display the results. I have been able to do this. My problem is when my query selects more than one field I am unsure on how to read that into an array or something like that. All the results I have done so far have had multiple results but only from one field in the database. Here is my serlvet and jsp code. If some one could tell me how to read multiple field into an array and display them on a jsp page that would be great. Thank you
    Servlet
    package nnet;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.security.Principal;
    import java.sql.*;
    import java.sql.DriverManager;
    * <p>Title: NNET</p>
    * <p>Description: Northland Intranet</p>
    * <p>Copyright: Copyright (c) 2004</p>
    * <p>Company: NMI</p>
    * @author not attributable
    * @version 1.0
    public final class home
    extends HttpServlet {
    //Initialize global variables
    //Initialize queries
    private static final String USERQUERY =
    "SELECT public.tblindividual.firstname as firstname " +
    "FROM public.tblloginname " +
    "INNER JOIN public.tblindividual ON (public.tblloginname.indlink = public.tblindividual.indid) " +
    "WHERE LOWER(public.tblloginname.loginname) = LOWER(?)";
    private static final String MAINLINKQUERY =
    "SELECT public.nnetsection.name " +
    "FROM public.nnetsection " +
    "WHERE public.nnetsection.posted = 'true'";
    private static final String ANOUNCEMENTQUERY =
    "SELECT public.nnetanouncement.anouncement, to_char(nnetanouncement.postdate,'MonthDD, YY') as postdate " +
    "FROM public.nnetanouncement " +
    "ORDER BY public.nnetanouncement.postdate DESC";
    public void init() throws ServletException {
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException {
    Connection con = null;
    PreparedStatement stmt = null;
    //Initialize Resultset objects
    ResultSet namers = null;
    ResultSet mainlinkrs = null;
    ResultSet anouncementrs = null;
    ResultSet anouncementdaters = null;
    //Initialize Array Lists
    ArrayList mainlinkresults = new ArrayList();
    ArrayList anouncementresults = new ArrayList();
    String firstnameresult = null;
    Principal user = request.getUserPrincipal();
    String username = user.getName();
    Properties props = new Properties();
    InputStream in = getServletContext().getResourceAsStream(
    "/WEB-INF/sql.properties");
    props.load(in);
    in.close();
    //get Users login name to pass on
    try {
    Class.forName(props.getProperty("connection.driver"));
    con = DriverManager.getConnection(props.getProperty("connection.url"), props);
    stmt = con.prepareStatement(USERQUERY);
    stmt.setString(1, username);
    namers = stmt.executeQuery();
    while (namers.next()) {
    firstnameresult = namers.getString("firstname");
    //results.add(namers.getString("firstname"))
    catch (SQLException ex1) {
    catch (ClassNotFoundException ex) {
    finally {
    if (stmt != null) {
    try {
    stmt.close();
    catch (SQLException e) {
    e.printStackTrace();
    stmt = null;
    if (con != null) {
    try {
    con.close();
    catch (SQLException e) {
    e.printStackTrace();
    con = null;
    //get the main links to pass on
    try {
    Class.forName(props.getProperty("connection.driver"));
    con = DriverManager.getConnection(props.getProperty("connection.url"), props);
    stmt = con.prepareStatement(MAINLINKQUERY);
    mainlinkrs = stmt.executeQuery();
    while (mainlinkrs.next()) {
    mainlinkresults.add(mainlinkrs.getString("name"))
    catch (SQLException ex1) {
    catch (ClassNotFoundException ex) {
    finally {
    if (stmt != null) {
    try {
    stmt.close();
    catch (SQLException e) {
    e.printStackTrace();
    stmt = null;
    if (con != null) {
    try {
    con.close();
    catch (SQLException e) {
    e.printStackTrace();
    con = null;
    //get the announcements to pass on
    try {
    Class.forName(props.getProperty("connection.driver"));
    con = DriverManager.getConnection(props.getProperty("connection.url"), props);
    stmt = con.prepareStatement(ANOUNCEMENTQUERY);
    anouncementrs = stmt.executeQuery();
    while (anouncementrs.next()) {
    anouncementresults.add(anouncementrs.getString("anouncement"));
    catch (SQLException ex1) {
    catch (ClassNotFoundException ex) {
    finally {
    if (stmt != null) {
    try {
    stmt.close();
    catch (SQLException e) {
    e.printStackTrace();
    stmt = null;
    if (con != null) {
    try {
    con.close();
    catch (SQLException e) {
    e.printStackTrace();
    con = null;
    request.setAttribute("firstname", firstnameresult);
    request.setAttribute("mainlink", mainlinkresults);
    request.setAttribute("anouncement", anouncementresults);
    RequestDispatcher rd =
    request.getRequestDispatcher("home.jsp");
    rd.forward(request, response);
    //Clean up resources
    public void destroy() {
    JSP Page
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
    <html>
    <head>
    <title>
    index
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
    <!--
    body {
         margin-left: 0px;
         margin-top: 0px;
         margin-right: 0px;
         margin-bottom: 0px;
    -->
    </style></head>
    <body bgcolor="#008000">
    <table width="100%" border="1" cellspacing="0" bordercolor="#000000">
    <tr>
    <td bgcolor="#FFFFFF"><h1>Welcome to NNET <c:out value="${requestScope.firstname}" /></h1>
    </td>
    </tr>
    </table>
    <br>
    <table width="100%" border="0" cellspacing="0">
    <tr>
    <td width="150"><table width="100%" border="1" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF">
    <tr>
    <td><strong>Main Links </strong></td>
    </tr>
    <c:forEach var="item" items="${requestScope.mainlink}">
    <tr>
    <td valign="top"><c:out value="${item}"/></td>
    </tr>
    </c:forEach>
    </table>
    <p> </p></td>
    <td><table width="100%" border="0" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
    <td valign="top"><h2>Announcements</h2>
    <p>
    <c:forEach var="item" items="${requestScope.anouncement}">
    <c:out value="${item}" />
    </c:forEach>
    </p>
    </td>
    </tr>
    </table></td>
    <td width="150"> </td>
    </tr>
    </table>
    </body>
    </html>

    OK if you look at the code I pasted above I have doen that. I hav ethat book and it is good. My question is how do I get the data read into a multidemisional array or an arraylist like I am using in the code above so I can access that on the jsp page. Can you give an example. Here is what I want . I have a table called anouncements with 3 fields (ID, name, url) I am returning say 10 results. I want to store them in a single arraylist or multideminsional array and call them on the jsp page. What syntax would I use on the servlet and on the jsp page for this? I know how to do it as seen above when I return only one field with many results from the database. Thank you in advance for any help

  • Follow-up Basic XML Questions

    First, I apologize to the board in advance because I started a very similar topic already. I know this can be annoying but I think I'm worried that people will ignore my original post because there was already a reply to it. I added 2 follow up posts and nobody has responded. It could well be because they feel that my questions were already answered. After reading and re-reading the person who replied to my original question I did start to pick up many answers from his post. However, I guess I have some follow-up questions and felt compelled to start a new thread to get this "out there" again. I promise to try not to do this again and, once again, I apologize for starting multiple similar topics. Anyway, here goes my follow-up questions...
    I'm pretty new to XML but I've been reading an article on msdn about it and listed some code from the article at the bottom of this post.
    I have some questions about namespaces. From what I understand, a namespace is a unique identifier (it's a string). The thing that's bugging me though is this line...
    <x:transform version='1.0' xmlns:x='http://www.w3.org/1999/XSL/Transform'>
    Maybe I'm wrong, but my gut feeling is that this particular namespace has a special meaning (in other words, it goes beyond being just a unique identifier). Am I correct on this?
    From other stuff I've read I have another gut feeling that there are certain namespaces that somehow have schemas attached to them automatically. I've read that a schema can be "namespace aware". So, as a guess at the answer to my original question - are there certain namespaces that are something like "keywords" (similar to the concept of "keywords" in programming languages)? And is the "big deal" about these particular namespaces that they have schema definitions attached to them somehow? Any help would be GREATLY appreciated!
    EXAMPLE CODE FROM THE MSDN SITE:
    <x:transform version='1.0'
    xmlns:x='http://www.w3.org/1999/XSL/Transform'
    >
    <x:template match='/'>
    <hello_world/>
    </x:template>
    </x:transform>

    this particular namespace has a special meaning .... Am I correct on this?Yes, that namespace has a "meaning", but only to a program that implements the XSLT language. Likewise a "purchase order" namespace has a "meaning", but only to a program that is designed to read XML with that namespace and convert it to purchase orders in somebody's accounting system. (Just as the codes 'A', 'C', and 'D' could mean 'Add', 'Change', and 'Delete' to a program that maintains a database.) Similarly element names have a "meaning", but only to a program that is designed to understand that "meaning". A Java program has a "meaning" but a COBOL compiler doesn't understand that "meaning".
    From other stuff I've read I have another gut feeling that there are certain namespaces that somehow have schemas attached to them automatically.Not that I've ever heard of.

  • XML Question for web.xml file for LiteWebServer

    Hi,
    I have no clue of wut tags are required in the web.xml file.
    Currently the following code is in my web.xml file and i am trying to run servlets that are located under web-inf/*.class
    Pls tell me wuts wrong....
    Do i need those mime-mapping tags, session and welcome tags.......... ?
    Right now i just want those 2 servlets to work
    And wut is this encoding ="UTF-8" in the first line of the xml file. Wut does that do... ? ARe there any others
    Any help would b greatly appreciated
    Thanks
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app id="WebApp_1">
    <display-name>PDMPortal</display-name>
    <session-config id="SessionConfig_1">
    <session-timeout>60</session-timeout>
    </session-config>
    <mime-mapping id="MimeMapping_1">
    <extension>htc</extension>
    <mime-type>text/x-component</mime-type>
    </mime-mapping>
    <welcome-file-list id="WelcomeFileList_1">
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet>
    <servlet-name>HelloWorldExample</servlet-name>
    <servlet-class>HelloWorldExample</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>HelloWorld</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HelloWorldExample</servlet-name>
    <url-pattern>HelloWorldExample</url-pattern>
    </servlet-mapping>
    </web-app>

    Try putting your servlets in the WEB-INF\classes directory.

  • XSLT, XML Question???

    I've recently found that I can use XSLT to transform XML docs into SQL using x-path... Is there any documentation out there referencing a transformation using x-query???? I've searched the web but have not seem much on this...
    Any direction would be greatly appreciated.

    XSLT doesn't use XQuery. So it's not surprising you haven't found much documentation about using XQuery in XSLT. You might want to direct questions like this one to an XSLT forum rather than a Java forum.

  • Sun-faces-config.xml question

    Hello all,
    maybe this question is a bit silly, but i�m a newbie to this. I�m developing a complib file with a custom component; and I want to add custom properties to it. As far as I�ve done, i�m able to add custom string properties via the "StringPropertyEditor"
    All this is done in the sun-faces-config.xml file, and when I declare a property which can be set via a combo-box, this is, with a "SelectOneDomainEditor" in the sun-faces-config.xml, I don�t know how to populate this combo with data to be shown so it can be selected in the properties window.
    I�d be truly grateful to anyone who can help me out, maybe a short sample or fraction of a sun-faces-config would be fine.
    Thanks everyone in advance, and sorry for the long read,
    MANUEL ANS�N.

    Hi ,
    The follwing link may probably answer your query.
    http://swforum.sun.com/jive/thread.jspa?threadID=50215&tstart=15
    Regards.,

  • JSP xml syntax, taglibs not found

    Hello,
    I have JSPs look so:
    <?xml  version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE jsp:root [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <jsp:root version="1.2"
              xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:afc="http://afclabs.com/tags/afc"
              xmlns:c="http://java.sun.com/jstl/core">
    <jsp:directive.page language="java" contentType="text/html; charset=iso-8859-1"/>
    <afc:page>
    <head>
    <title></title>
    </head>
    <body>
    </body>
    </afc:page>
    </jsp:root>[/code:1:449443877c]
    If I use Tag Libraries panel, to insert , for example <c:out> tag, then the tag will be inserted along with this line: <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>, like so:
    [code:1:449443877c]<?xml  version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE jsp:root [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <jsp:root version="1.2"
              xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:afc="http://afclabs.com/tags/afc"
              xmlns:c="http://java.sun.com/jstl/core">
    <jsp:directive.page language="java" contentType="text/html; charset=iso-8859-1"/>
    <afc:page>
    <head>
    <title></title>
    </head>
    <body>
    <c:out value="test" default="test"/>
    </body>
    </afc:page>
    </jsp:root>[/code:1:449443877c]
    I don't need this line, because the tag libraries are defined in the <jsp:root> tag.
    How can I stop the automatically insert of this line ?
    How to make, that the Nitrox "undestand" this tag:
    [code:1:449443877c] <jsp:root version="1.2"
              xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:afc="http://itoolabs.com/tags/afc"
              xmlns:c="http://java.sun.com/jstl/core">[/code:1:449443877c] ?
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    http://java.sun.com/products/jsp/docs.html
    To my knowledge, only Tomcat 5 will use the 2.0 specs. Other servers will use the 1.2 spec, but the server docs should state which JSP spec they support.
    I found the 'Card' PDF the most helpfull. The 'Reference' is quick and easy, but you don't get as much info as quickly, IMO (for example I couldn't find the information to help here in the 'Reference' but it was right on top in the 'Card')

  • JSP & XML

    I am trying to create an XML file via a JSP. I want to be able to take the user input and store it in an XML whihc can be appeneded. The problem is that I can take the user input and create the XML file but if the user tries again this happens:
    <?xml version="1.0"?>
    <users>
    <user>
    <username>bob</username>
    <password>bob</password>
    </user>
    </users>
    <?xml version="1.0"?>
    <users>
    <user>
    <username>mjs</username>
    <password>mjs</password>
    </user>
    </users>
    Below is the section of code which I have been using:
    <file:writeFile source="/WINDOWS/Desktop/JSPs/Xslt/redneck/users.xml" append="true"><?xml version="1.0"?>
    <users><% if(user != null){
    %>
    <user>
    <username><%=user%></username>
    <password><%=pass1%></password>
    </user>
    <%}%></users>
    </file:writeFile>
    PLEASE somebody show me the light!!!

    So your problem is that the new data gets appended to the old data? In that case, although I know nothing about the tag you are using, I would hazard a guess that this attribute is the problem:
    append="true"

Maybe you are looking for

  • Level 3 postscript in Photoshop

    A technician for our CTP system says that Photoshop CS3 does not directly support postscript level 3. He says that Photoshop does not take advantage of 1024 levels of gray and thus is more prone to banding than gradients created in InDesign or Illust

  • Question on Serial Nos

    We require serial numbers to be entered when doing a material movement to stock or to another storage location. Sometimes the range of these numbers can be 50+ numbers but that range consecutively. Is there a way to put the range from beginning to en

  • Want to add new material group plz where I can Add it

    Dear experts I want to add material group can you help where I can add it. The material groups are saved in table T0123 . This table is having view also can I enter the value in View or I have to go to SPRO to add new material group. plz help me as I

  • KT4V fails to boot

    Alright, I am a loyal MSI owner, I run a KT3 ULTRA 333 on my personal box, alright. I was / am building a box for a good family friend of our and bought a KT4V not one but 2 the first faild to read the perfectly good DIMM of PC2100 non ecc, so then w

  • Advice for general iPod use?

    I need some help - ive havent had my iPod for a year and ive sent it back theree times. Ive had the folder! sign but now im getting the sad iPod. Is there something im doing wrong EVERY time. After reading the boards ive been use firewire to update w