princehyderabad
asked on
JSP include - unwanted xml attribute value display
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</Pow erSupply>
</PowerSupplyStatus>
[-------]
MY JSP code:
[--------------------]
<jsp:include page="/resource/Document" /> [THIS IS SERVLET WHOSE OUTPUT IS ABOVE]
<%
ServletContext context = getServletContext();
Document doc1 = (Document)context.getAttri bute(id+": "+ServletC onstants.D OC);
TransformerFactory tFactory = TransformerFactory.newInst ance();
InputStream is = context.getResourceAsStrea m("/styles heets_new. xsl");
Transformer transformer = tFactory.newTransformer(ne w StreamSource(is));
Source source = new DOMSource(doc1);
transformer.transform(sour ce, 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
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</Pow
</PowerSupplyStatus>
[-------]
MY JSP code:
[--------------------]
<jsp:include page="/resource/Document" /> [THIS IS SERVLET WHOSE OUTPUT IS ABOVE]
<%
ServletContext context = getServletContext();
Document doc1 = (Document)context.getAttri
TransformerFactory tFactory = TransformerFactory.newInst
InputStream is = context.getResourceAsStrea
Transformer transformer = tFactory.newTransformer(ne
Source source = new DOMSource(doc1);
transformer.transform(sour
%>
[--------------------]
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
can you post your xsl?
ASKER
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>
<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>
ASKER
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. lastIndexO f(request. getServlet Path()));
URL url = new URL(contextURL + childUrl );
HttpURLConnection conn = (HttpURLConnection)url.ope nConnectio n();
conn.setDoInput(true);
TransformerFactory tFactory = TransformerFactory.newInst ance();
Transformer transformer = tFactory.newTransformer( new StreamSource("stylesheets_ new.xsl") );
transformer.transform(new StreamSource(conn.getInput Stream()), new StreamResult(out));
%>
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.
URL url = new URL(contextURL + childUrl );
HttpURLConnection conn = (HttpURLConnection)url.ope
conn.setDoInput(true);
TransformerFactory tFactory = TransformerFactory.newInst
Transformer transformer = tFactory.newTransformer( new StreamSource("stylesheets_
transformer.transform(new StreamSource(conn.getInput
%>
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?
<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?
ie: get rid of the line:
<jsp:include page="/resource/Document" />
:-)
<jsp:include page="/resource/Document" />
:-)
ASKER
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.getAttri bute(id+": "+ServletC onstants.D OC);" which is in JSP code.
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.getAttri
Is the XML dumped into the page when you view source on the HTML?
what does
<jsp:include page="/resource/Document" />
actually include?
what does
<jsp:include page="/resource/Document" />
actually include?
ASKER
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.getAttri bute(id+": "+ServletC onstants.D OC);"
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=""... ???
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.getAttri
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=""... ???
ASKER
I GOT THE ANSWER MYSELF THRU OTHER RESOURCES:
Simply replace <jsp include> code with
<SERVLET NAME="Servlet" CODE="Servlet.class" CODEBASE="url">
</SERVLET>
Simply replace <jsp include> code with
<SERVLET NAME="Servlet" CODE="Servlet.class" CODEBASE="url">
</SERVLET>
Cool :-)
If you post a link to this Q here: https://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
If you post a link to this Q here: https://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
Yup, fair enough :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.