?
Solved

JSP include - unwanted xml attribute value display

Posted on 2004-09-15
13
Medium Priority
?
215 Views
Last Modified: 2013-11-19
Hello,

I have a issue with jsp include. I'm including this servlet which gives output as XML.  This XML output is something like this:

[-------]
   <ServerCpuUsage Status="normal" Value="1" />
- <FanStatus Status="normal">
  <Fan DisplayName="Fan 1" Status="normal">on</Fan>
  </FanStatus>
- <PowerSupplyStatus Status="critical">
  <PowerSupply DisplayName="Power supply 1" Status="critical">off</PowerSupply>
   </PowerSupplyStatus>
[-------]


MY JSP code:

[--------------------]
<jsp:include page="/resource/Document" /> [THIS IS SERVLET WHOSE OUTPUT IS ABOVE]
 <%  
 
         ServletContext context = getServletContext();
         Document doc1 = (Document)context.getAttribute(id+":"+ServletConstants.DOC);  
         TransformerFactory tFactory = TransformerFactory.newInstance();
         InputStream is = context.getResourceAsStream("/stylesheets_new.xsl");
         Transformer transformer = tFactory.newTransformer(new StreamSource(is));
         Source source = new DOMSource(doc1);
         transformer.transform(source, new StreamResult(out));
%>
[--------------------]

When I run my JSP, using stylesheet the output is correct, but I'm getting extra with stuff bcoz of jsp include: Like this:

OUTPUT:
===================
onoff
[correct stylesheet output.....]
===================

I dont want that "onoff" which is attribute value from <fan> and <powersupply> if you can see the XML output.
Is there any way to get rid of this "on" and "off" from attribute <fan> and <powersupply> of auto generated servlet. Do I need to replace jsp include with something else ?? Please help

Regards,
H
0
Comment
Question by:princehyderabad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
13 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12068720
can you post your xsl?
0
 

Author Comment

by:princehyderabad
ID: 12068886
XSL is to large and u may get confuse, to make it easy, I hv copied below the xsl part which reflects the above Question. This is the XSL.

<xsl:for-each select="Inventory">

    <xsl:for-each select="ServerCpuUsage">
    <xsl:for-each select="@Value">
    <xsl:value-of select="." /> %
    </xsl:for-each>
    </xsl:for-each>

      <xsl:for-each select="Fan">
      <xsl:value-of select="@DisplayName"/>
     <xsl:value-of select="@Status"/>
     </xsl:for-each>

      <xsl:for-each select="PowerSupply">
      <xsl:value-of select="@DisplayName"/>
     <xsl:value-of select="@Status"/>
     </xsl:for-each>

</xsl:for-each>
0
 

Author Comment

by:princehyderabad
ID: 12068937
Let me tell you XSL is has notthing to do with "onoff" display stuff. Because when I tried my JSP code below, there was no "onoff" extra display. And the stylesheet was same. Its only bcoz of change of JSP code and additing the jsp include.

My Old JSP code which displayed correctly with no extra display of "onoff" ...
<%
   String childUrl = "/resource/Document";
   StringBuffer reqURL = request.getRequestURL();
   String contextURL = reqURL.substring(0,reqURL.lastIndexOf(request.getServletPath()));    
   URL url = new URL(contextURL + childUrl );  
       
   HttpURLConnection conn = (HttpURLConnection)url.openConnection();            
   conn.setDoInput(true);                
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer( new StreamSource("stylesheets_new.xsl") );
   transformer.transform(new StreamSource(conn.getInputStream()), new StreamResult(out));
%>
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 35

Expert Comment

by:TimYates
ID: 12073654
Errrr...  the line:

<jsp:include page="/resource/Document" />

will put the words

    onoff

At the top of the page, as the browser will try to render the XML as HTML, so strip out all the tags (as they are not valid HTML tags), and display the results...

If you view the source of the page, the XML will be there (at the top of the page), but in the browser, it will just look like "onoff"

Why do you include an XML document into your JSP?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12073657
ie:  get rid of the line:

<jsp:include page="/resource/Document" />

:-)
0
 

Author Comment

by:princehyderabad
ID: 12077024
hi TimYates,

Dont you think it would be easy for me to get rid of that include, I hv to include in order to run this line
" Document doc1 = (Document)context.getAttribute(id+":"+ServletConstants.DOC);" which is in JSP code.


0
 
LVL 35

Expert Comment

by:TimYates
ID: 12079313
Is the XML dumped into the page when you view source on the HTML?

what does

<jsp:include page="/resource/Document" />

actually include?
0
 

Author Comment

by:princehyderabad
ID: 12086602
I'll explain in my own terminology.
That include,  includes the Servlet Output which gives XML.
If you dont include <jsp:include page="/resource/Document" />
this will not work as said earlier: " Document doc1 = (Document)context.getAttribute(id+":"+ServletConstants.DOC);"

Now what this doc1 has is, the DOM XML which is produce by include servlet.
Why I need doc1, bcoz transformation need, xml and stylesheet. Stylesheet file name you can see in the code above. And XML is what we getting after including the include tag and in doc1 gettting from ServletContext.

Is there any other way to replace include tag, something like <servlet name="" class=""... ???
0
 

Author Comment

by:princehyderabad
ID: 12104425
I GOT THE ANSWER MYSELF THRU OTHER RESOURCES:

Simply replace <jsp include> code with
<SERVLET NAME="Servlet" CODE="Servlet.class" CODEBASE="url">
</SERVLET>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12105363
Cool :-)

If you post a link to this Q here: http://www.experts-exchange.com/Community_Support/

You can get this question closed, and your points refunded :-)

Good luck!

Sorry I couldn't help more :-(

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12107290
Yup, fair enough :-)
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12148825
Closed, 300 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question