Whitespace in XML-Style JSP

Hi,
I am having a slight issue with the XHTML content generated by a JSP. The output is stripped entirely of all whitespace, such that the content is all on one line. I have a request from one of our content writers to view the source "nicely". Oddly, in all of my searches for this problem, I have found people experiencing the opposite problem.
Suppose I have a JSP like so:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page language="java" contentType="text/html;charset=ISO-8859-1"/>
<html>
<head>
     <title>A JSP Page</title>
</head>
<body>
     <table>
          <tr>
               <td>Table Cell</td>
          </tr>
     </table>
</body>
</html>
</jsp:root>The resulting output is:
<html><head><title>A JSP Page</title></head><body><table><tr><td>Table Cell</td></tr></table></body></html>How can I get the output to have the same indentation as the source?
I am using Tomcat 4.1.29.
Thanks!

Hi Syed,
Try these links:
<a href="http://www.javaranch.com/newsletter/Feb2002/xmljsp.html">Exploring JSP Documents (XML Style JSP Pages)</a> --> an excellent overview of the benefits of JSP Documents (XML Style JSPs) over standard JSP Pages.
<a href="http://www.webmonkey.com/webmonkey/01/22/index3a.html?tw=programming">Intro to JSP</a>
You can also try googling for "XML Style JSP"...
Regarding books on JSP 2.1 and Servlet 2.5 -- I really can't believe that there are none available! Have you tried searching on amazon?
HTH!
-Vladimir

Similar Messages

  • Include in XML style

    I am trying to convert some JSP files to an XML style.
    This is a snip from taglibs.jsp:
    <jsp:root
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:bean="http://struts.apache.org/tags-bean"
    xmlns:bean-el="http://struts.apache.org/tags-bean-el"
    xmlns:myapp="/WEB-INF/myapp.tld"
    version="1.2">
    <jsp:directive.page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" />
    <html:xhtml />
    </jsp:root>
    The problem is that I can't find a way to include it in other JSP pages.
    The following obviously doesn't work.
    <jsp:root
    xmlns:jsp="http://java.sun.com/JSP/Page"
    version="1.2">
    <jsp:directive.include file="/common/taglibs.jsp" />
    </jsp:root>
    Any suggestion?
    Marcello

    How about using the jsp:include instead of the jsp:directive.include? Is there a reason you need the static include (the directive), or are you able to just include the finished product of the included JSP(the jsp:include)?
    <jsp:include page="/common/taglibs.jsp"/>

  • Can the XML style sheet be embedded in the report file?

    My customer would like to be able to share test reports with several locations. The problem is that sending just the XML report file is not enough. The report file points to a style sheet that must exist at the specified path on the destination PC. It creates problems when one simply wants to email over a test report. I have customized the style sheet slightly to make things easier to read. So, can I embed my custom style sheet in each report file?
    Thanks,
    Daniel L. Press
    PrimeTest Corp.
    www.primetest.com

    Hi,
    The XML style sheet should not be embedded into the report file. Since XML would represent raw data, you would not include information on how to interpret it. However, there is a way for you to easily reference your style sheet, even when it is on another computer.
    1) Go to Configure >> Report Options in TestStand, and change the style sheet file to your style sheet.
    2) Uncheck the "Store Absolute File Path" box.
    3) Make sure the style sheet is in the same folder as your report.
    You can view this on any computer, and now a relative path is now being used to reference the file.
    Allen P.
    NI

  • Best way to create, modify, XML with JSP ?  HELP

    Hi friends,
    As i am new to XML,
    I know there are two APIs used for XML processing, i want to know as a begineer level, which API
    is easy and good to implement XML with JSP.
    1) SAX
    2) DOM
    i want to make a log file in XML, so on web page it will be displayed on HTML form through XSL.
    Since there is good tutorial on http://www.w3schools.com/dom
    but i think its HTML dom
    I want XML procession through JAVA CODE , what should i use ? and give some good tutorials on XML DOM
    that is used with JAVA / JSP.
    HELP.
    Edited by: Ghanshyam on Sep 19, 2007 3:24 PM

    Well what i think is you gonna checkout with your requirements before implementing any of the popular XML parsing mechnisms.
    If you are intrested in faster processing @sacrifising a gud amount of your Memory,DOM is the one which you are looking for.
    If you are instrested in Managing your memory and but if you are ok with sacrifising speed SAX is the best solution.it works on what is called a push technology.
    and if you think either way you might have to look towards a pull parser which is StAX (Streaming API for XML Parsing)
    it'd be a gr8 idea if you can go through the below article which explians about each of the parsing mechanisms
    http://www.stylusstudio.com/xml/parser.html#*
    coming back to helpful resources as far java is concern checkout the below link which might be of some help.
    and the main thing is that all of these parser there is a defined specification you might find implementations of different vendors on this.
    eg:Sun Provides one with JDK itself,same as IBM provides one,oracle does the same & so on...
    your first task would be to focus on one such implementation which can cater your requirements.
    DOM:*
    Basic Parsing Objects / Interfaces Involved while DOM parsing:
    http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html
    Breif Overview & few important API details:
    http://www.developerlife.com/domintro/default.htm
    Simple Example:
    http://www.brics.dk/~amoeller/XML/programming/domexample.html
    Others:
    http://www.roseindia.net/xml/dom/
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM.html#wp79994
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/1_read.html
    SAX:*
    http://www.javacommerce.com/displaypage.jsp?name=saxparser1.sql&id=18232
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/index.htm
    http://java.sun.com/developer/Books/xmljava/ch03.pdf
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPSAX.html#wp69937
    http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=6
    StAX:*
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP2.html
    http://javaboutique.internet.com/tutorials/stax/
    http://today.java.net/pub/a/today/2006/07/20/introduction-to-stax.html
    Hope this might be of some help :)
    REGARDS,
    RaHuL
    http://weblogs.java.net/blog/spericas/archive/2006/04/sun_stax_parser.html

  • How to Pass values from XML to JSP??? Urgent Please Help me

    Hi guys,
    I am new to XML, I want to pass values from XML to JSP. I have a xml file with attributes, I should send this values to a JSP file. How is it??? Please Help guys.... its very urgent. Please send me how to do it with an example or atleast any urls related that....
    Looking for ur favourable reply.
    Thanks in advance,
    Sridhar

    in a servlet :
    parse your xml file (see how at the end of the post) and
    put the values you want in the request attributes
    request.setAttribute("value1", value1);
    ...redirect to the jsp
    in the JSP:
    get the wanted attributes:
    String value1=(String)request.getAttribute("value1");To learn how to parse a xml file, pay a look at this page, it explains how to read the XML document to build an object representation, and then how to navigate through this object to get the data
    http://labe.felk.cvut.cz/~xfaigl/mep/xml/java-xml.htm

  • Creating XML using JSP

    Hi I want to create a xml using JSP For eg I want to create a report
              and I want to take all the data required for the report from the user
              and want to put all the information in a session and whenever a user
              wants to see the html output I should be able to parse the xml file
              and show it to user.
              I know it is doable but I am confused about storing the data in
              session and concerting that data into XML file any help would be
              great.
              Thanks,
              Preeti
              

    Sounds like you might want to look at XML data binding. Something like JAXB
              or Castor can create an object that can be turned into XML by merely calling
              a single method and probably streamed to Xalan or whatever to create HTML.
              However, don't quote me on this - I am having enough troubles with trying to
              get the compiled Objects to be as I wish. Basically, they both take your
              DTD with an extra file that defines the types to be used in the classes -
              i.e. instead of string int might be used - and which tags to turn into
              classes and general information such as this about the output of your
              classes. You then simply call Unmarshal (for both castor and JAXB) and it
              loads the file from the selected input stream into the created object, you
              edit the object, what ever - store it on the server... and call Marshal to
              get back the xml... as this is all using streams it could be passed to Xalan
              for processing i think...
              Hope I've helped, and answered your question a little!
              "Preeti Sikri" <[email protected]> wrote in message
              news:[email protected]...
              > Hi I want to create a xml using JSP For eg I want to create a report
              > and I want to take all the data required for the report from the user
              > and want to put all the information in a session and whenever a user
              > wants to see the html output I should be able to parse the xml file
              > and show it to user.
              >
              > I know it is doable but I am confused about storing the data in
              > session and concerting that data into XML file any help would be
              > great.
              >
              > Thanks,
              > Preeti
              

  • Request xml, process jsp..

    Hello
    My English abillity very poor. sorry...
    My homepage base on xml(not servelet, jsp)
    so user connect a.xml...
    a.xml+a.xsl combine... so user can view homepage....
    but I want to....
    user request a.xml
    a.xml call specific jsp process and make new b.xml...
    and b.xml+a.xsl... > view new page.....
    so How can I connect a.xml + process.jsp.....
    a.xml must call process.jsp...
    Help me

    Have the XML page call a servlet in the usual HTML manner passing what ever parameters needed. In the Srevlet do what ever processing needed. In the response back to the browser do:
    res.setContentType("text/xml");
    pw = res.getWriter();
    pw.print(xmlString);
    pw.flush();
    pw.close();
    where xmlString is the desired xml in a String. You could also play around with getOutputStream if you prefer.

  • XML Style sheet

    Does anyone know how to create xml style sheet from oracle report. Or is it possible thru the tool ?
    Please let me know.
    Thanks
    Rakesh

    You will need to check a few things:
    a) Check that the Integration Option in the HFM Adapter "FDM WEB SERVER NAME" matches the value that the users are using to access FDM.
    http://<fdmwebservername>/HyperionFDM
    Make sure that the server host name is entered into this option.
    b) Check that the XML file type on the users workstation is configured to open with Internet Explorer and not the XML Editor.  You can do this by creating a text document named test.xml and right-clicking on it and choose "properties" and update the program to open the file to Internet Explorer and save.
    c) Make sure that the FDM Web Site is in the users trusted sites in the IE Browser
    d) Make sure that the "Automatically prompt for file downloads" and "Automatically Prompt for Active-X Controls" options are set to Enabled in the IE Settings.

  • Create XML using JSP

    I am trying to create and send an XML file back to browser where XSL will be
              applied. I am using wl6.0 sp2
              I tried like this
              <%@ page contentType="text/xml" %>
              <%
              out.println("<?xml version=\"1.0\"?>") ;
              out.println("<books>");
              out.println("<title>") ;
              out.println("XML Programming") ;
              out.println("</title>") ;
              out.println("</books>") ;
              %>
              But the browser is blank.
              Thanks
              shaikjava
              

    Also, valid XML documents have no whitespace before the <?xml ...?>
              declaration.
              Sam
              "Cameron Purdy" <[email protected]> wrote in message
              news:[email protected]...
              > There are lots of reasons why the browser could be blank. Judging from the
              > JSP you provided below, I could not even begin to guess at what you are
              > doing to prevent the browser from working.
              >
              > > <%
              > > out.println("<?xml version=\"1.0\"?>") ;
              > > out.println("<books>");
              > > out.println("<title>") ;
              > > out.println("XML Programming") ;
              > > out.println("</title>") ;
              > > out.println("</books>") ;
              > > %>
              >
              > Do you mean you did all that when you could have just:
              >
              > <?xml version="1.0"?>
              > <books>
              > <title>
              > XML Programming
              > </title>
              > </books>
              >
              > That is what JSPs are for, after all!!! Don't put markup language inside
              > code inside a JSP!!! You're going to give someone a friggin heart attack.
              >
              > Remember:
              > servlets = code
              > jsps = raw content
              >
              > You can put content in servlets by embedding it in the code. You can put
              > code in jsps by embedding it in the content.
              >
              > Peace,
              >
              > --
              > Cameron Purdy
              > Tangosol Inc.
              > << Tangosol Server: How Weblogic applications are customized >>
              > << Download now from http://www.tangosol.com/download.jsp >>
              >
              >
              > "chand" <[email protected]> wrote in message
              > news:[email protected]...
              > > I am trying to create and send an XML file back to browser where XSL
              will
              > be
              > > applied. I am using wl6.0 sp2
              > >
              > > I tried like this
              > >
              > > <%@ page contentType="text/xml" %>
              > >
              > > <%
              > > out.println("<?xml version=\"1.0\"?>") ;
              > > out.println("<books>");
              > > out.println("<title>") ;
              > > out.println("XML Programming") ;
              > > out.println("</title>") ;
              > > out.println("</books>") ;
              > > %>
              > >
              > > But the browser is blank.
              > >
              > > Thanks
              > > shaikjava
              > >
              > >
              > >
              > >
              > >
              > >
              > >
              >
              >
              

  • How to  display / Embed XML in jsp ?

    hi, i have following files in my project and i would like to display stocks.xml file in jsp, when i open stocks.xml file in browers , it opens nice with the xsl style , but i can't seem to add it in my jsp. ?. my jsp only displays simple raw text from xml not the style as it is shown in browser by just clicking the stocks.xml file.......... thanks in advance ...
    ==============index.jsp=====================
    <%@ page contentType="text/xhtml" %>
    <html>
    <head>
    <title>Sample Application JSP Page</title>
    </head>
    <body bgcolor=white>
    <table border="0">
    <tr>
    <td align=center>
    <img src="images/logo.gif">
    </td>
    <td>
    <h1>Sample Application JSP Page</h1>
    application.
    </td>
    </tr>
    </table>
    <%= new String("Hello!") %>
    *{color:#ff6600}<jsp:include page="stocks.xml"></jsp:include>{color}*
    </body>
    </html>
    ==========stocks.xml======================
    <?xml version="1.0" encoding="UTF-8"?>
    {color:#339966}<?xml-stylesheet type="text/xsl" href="stocks.xsl"?>{color}
    <portfolio>
    <stock>
    <symbol>SUNW</symbol>
    <name>SunMicrosystems</name>
    <price>17.1</price>
    </stock>
    <stock>
    <symbol>AOL</symbol>
    <name>America Online</name>
    <price>51.05</price>
    </stock>
    <stock>
    <symbol>IBM</symbol>
    <name>International Business Machines</name>
    <price>116.10</price>
    </stock>
    <stock>
    <symbol>MOT</symbol>
    <name>MOTOROLA</name>
    <price>15.20</price>
    </stock>
    </portfolio>
    ===============================================
    ==================stocks.xsl======================
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
    <html>
    <head>
    <title>Stocks</title>
    </head>
    <body bgcolor="#ffffcc" text="#0000ff">
    <xsl:apply-templates />
    </body>
    </html>
    </xsl:template>
    <xsl:template match="portfolio">
    <table border="2" width="50%">
    <tr>
    <th>Stock Symbol</th>
    <th>Company Name</th>
    <th>Price</th>
    </tr>
    <xsl:for-each select="stock">
    <tr>
    <td>
    <i>
    <xsl:value-of select="symbol" />
    </i>
    </td>
    <td>
    <xsl:value-of select="name" />
    </td>
    <td>
    <xsl:value-of select="price" />
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </xsl:template>
    </xsl:stylesheet>
    Edited by: s_dhillon on Aug 31, 2008 8:15 PM
    Edited by: s_dhillon on Aug 31, 2008 8:21 PM

    Am not sure..
    may be by contentType

  • Need help in displaying XML in JSP

    Hi there,
    i'm a newbi in XML and Java - I have the following prob, think for most of u nothing very difficult (or better thought so, I've posted this question in different forums here, but nobody answers :)
    I get an XML response from a search engine, now I want to display the search result in a jsp.
    The result is stored in the session [I hope I figured out correctly ;)]
    with the following command ->
    this.pageContext.getSession().setAttribute(SEARCHRESULT, dSearchResult);
    [its from the java class, which generates the result]
    Result example ->
    <?xml version="1.0" encoding="UTF-8"?>
    <FindSearchResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xml/SearchResult.xsd">
    <Result Hits="2" Name="OfficeLand_en_US">
    <Items>
    <Item Score="250">
    <Field FieldNo="0" Name="ProductID">KqvAqAB1Tq0AAADnFthtpZvC</Field>
    <Field FieldNo="1" Name="CatalogCategoryID">gh0KAAFvj3wAAADiW8SMtr6o</Field>
    </Item>
    <Item Score="250">
    <Field FieldNo="0" Name="ProductID">4rwKAAFvtNYAAADiwdCMtr6o</Field>
    <Field FieldNo="1" Name="CatalogCategoryID">gh0KAAFvj3wAAADiW8SMtr6o</Field>
    </Item>
    </Items>
    <HitDistribution>
    <Hit Hits="75" Score="0"/>
    <Hit Hits="2" Score="250"/>
    </HitDistribution>
    </Result>
    </FindSearchResult>
    How many 'Field' elements exist, depends on the query.
    The result example is a response, which is send to my JSP page. It is stored in an variable under the name SEARCHRESULT (it's the result of a query in a search engine).
    My JSP page is the page, which should display the searchresult.
    So i need to know, how to programm something in my JSP page to check the SEARCHRESULT to display not the whole xml file. I just want to display all Items (compare with result example) -> The name of each existing FieldNo, the Score and the HitDistribution.
    Please help me :)

    hi there,
    first create a xml schema for the xml you will be receiving.
    use jaxb or castor with the schema and create a class.
    in your jsp unmarshal the xml result you are getting with the class
    generated by either jaxb or castor. the class will have methods that return you the required elements.
    get to know xml schema better and just a pass thru of jaxb or castor will solve the problem.
    vedha_g

  • How can I use SAX to Read XML in JSP?

    I created a class which extend DefaultHandler of SAX. I can use java to call this class and read XML data without any problems. But I can't call this class through JSP. Looks it didn't active startElement() when I called from JSP. Do you have any ideas on this case?
    ======================This is java call and works==============
    import java.io.*;
    import java.util.*;
    import ReadXmlSax;
    public class ReadElement
         public static void main(String argv[])
              ReadXmlSax r = new ReadXmlSax();
              Enumeration e = r.getAttribute("dre.xml","server","name");
              try{
                   while (e.hasMoreElements()) {
                   System.out.println((String)e.nextElement());}
              }catch(Throwable t){
                   t.printStackTrace();
    ======================================================================
    ========================This is jsp call but doesn't work=============
    <%@ page import = "java.util.*" %>
    <%@ page import = "java.io.*" %>
    <%@ page import = "ReadXmlSax" %>
    <html>
    <head><title>SAX Reader</title></head>
    <body>
    <%
    ReadXmlSax r = new ReadXmlSax();
    Enumeration e = r.getAttribute("dre.xml","server","name");
    while (e.hasMoreElements()) {
    out.println(e.nextElement());
    out.println("<br>");
    %>
    </body>
    </html>
    ======================================================================

    maybe you just simply can't reach dre.xml from your web server!

  • How to parse xml in jsp

    hei evryone!!!
    I'm a newbie in java, i just wanna know how to parse an xml file in JSP wherein i could remove nodes / modify certain nodes on the xml.
    Any suggestions / codes/ ideas would be much appreciated

    On my jsp page the default screen would be the list of traders. The user of the said application has the option to make some changes on the list either, add more trader/s on the list , remove specified trader/s on the list or edit certain trader/s. Furthermore, the user can also cancel the changes he made by clicking the cancel button or commit the modification he made by clicking the save button. When the application altered something, the changes must be reflected on the front end right away, but not on the database yet. In doing so, I intend to have two xml files , (1) the original xml file that is send to a CmsServlet (the servlet code that does the database commit) and (2) the temporary xml file that the page loads, which is initially just a copy of the original xml file. So whenever changes made at the frontend the temporary file is also altered, and when the save button is clicked, the temporary file is copied to original xml file to send the changes on the CmsServlet. But when the application user withdraws the changes he made at the frontend by clicking the cancel button , the original xml file is then copied to temporary xml file to reload the page.
    The access/modification on the temporary xml file is done in default.jsp.

  • Displaying data in xml using jsp

    how do we display data in database from jsp using xlst format in xml browser view

    how do we display data in database from jsp using xlst
    format in xml browser viewRefer this Post
    http://forum.java.sun.com/thread.jsp?forum=45&thread=482077&tstart=0&trange=15
    -Regards
    Manikantan

  • How to send/receive XML using JSP

    Hi,
    I'm new to all this JSP/XML stuff so apologies if this is trivial.
    I'm trying to send an XML file via HTTP POST using JSP. Anyone know how to do this?
    Once the XML has been sent, how do you use JSP to request the XML file? I've figured out how to parse it already.
    Also, is it possible to call xsql directly within JSP?
    Thanks!

    I'm trying to send an XML file via HTTP POST using JSP. Anyone know how to do this?The question is, does anybody understand what you mean by this. Let me take a guess. You want to upload an XML file to a server. If this guess is right, then the answer is don't use JSP to do that. JSP is for generating output to be sent to a client. Use a servlet to handle an upload. And you don't need to write it yourself, there are already several file-upload servlets available on the web.
    Second guess: you have a POST request that asks your server to send an XML file back to the client. If it's a static XML file you don't need a JSP or a servlet or anything, just let your web server handle it just like any other static file. If it's dynamically generated then there's an answer worth giving, but I doubt that this is your question. But if it is, let us know.

Maybe you are looking for

  • Airport Express extends 5 Ghz and 2.4 Ghz or just one at a time?

    I recently switched my dual band Time Capsule to use different names for the 5 Ghz and 2.4 Ghz networks. Will the Airport Express extend both or just one at a time, if so, which one will it extend? I have two Airport Express modules, bought a long ti

  • Enter Key cannot be used in find examples!!!

    I always use the enter key to enter or open a file/folder. But in LabVIEW example finder its not at all working.. Is there any special reason for not allowing the Enter key??? The best solution is the one you find it by yourself

  • Filter expressions on hidden fields

    I have 11 (eleven) different columns in a Report Builder 3.0 report. There can be multiple rows to this report depending on the date range selected. In those columns/rows, some data is hidden at times depending on another filter expression. The last

  • Loading realscale image from memorycard.

    Hi. I made a big image (3550 x 2100 pixels), which my Nokia 6125 didn't zoom enough on the normal Picture preview. So I decided to make a program for it, so I could see all the details from the pic, and move around on the image. (Like zoom, but I nee

  • About Test (webservices)

    Hai, ide:NetBeans 5.5 server:SunApplicationServer I developed the webservice .In this no errors when i am testing the webservice it gives the error like Service Class Not Generated why it is giving like that . If you know please send the reply as ear