Avatar of KenTan85
KenTan85 asked on

Problem with using PrintWriter inside a JSP

I have a JSP where i try to print a XML data.

After the Jsp executes, I see only the data in the screen. I should see a table along with the data(tables are defined in the XSL file).
Same code works when we use PrintWriter from with in the servlet.It didnt work inside a JSP.
Please suggest me what i am missing.

PS: I cannot create xml file and use transformation as i need to have pagination on the html page...
JSP Code:
 
PrintWriter out= response.getWriter();
out.write("xml version='1.0'?><?xml-stylesheet type='text/xsl' href='book.xsl'?><students> <student><name>Thomas</name><place>Delhi</place> <number>1111</number> <mark>78</mark></student>></students>"")
 
 
XSL Code:
 
XSL file is below : <?xml version="1.0"?> 
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
 
<xsl:template match="/"> 
<html> 
<body> 
<table border="2" bgcolor="yellow"> 
<tr> 
<th>Name</th> 
<th>Place</th> 
<th>Number</th> 
<th>Mark</th> 
</tr> 
 
<xsl:for-each select="students/student"> 
<tr> 
<td><xsl:value-of select="name"/> </td> 
<td><xsl:value-of select="place"/> </td>
<td><xsl:value-of select="number"/> </td> 
<td><xsl:value-of select="mark"/> </td> 
</tr> 
</xsl:for-each>

Open in new window

Web Languages and StandardsJSP

Avatar of undefined
Last Comment
rrz

8/22/2022 - Mon
rrz

I corrected the errors.  Please ask if you have any follow up questions.  
<%
out.write("<?xml version='1.0'?><?xml-stylesheet type='text/xsl' href='book.xsl'?>" +
          "<students> <student><name>Thomas</name><place>Delhi</place>" +
          "<number>1111</number> <mark>78</mark></student></students>");
%>


<?xml version="1.0"?>
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Name</th>
<th>Place</th>
<th>Number</th>
<th>Mark</th>
</tr>
 
<xsl:for-each select="students/student">
<tr>
<td><xsl:value-of select="name"/> </td>
<td><xsl:value-of select="place"/> </td>
<td><xsl:value-of select="number"/> </td>
<td><xsl:value-of select="mark"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ASKER
KenTan85

Hi,

I still can't get it work. Is Printwriter still able to be use in jsp to display xml with xsl???

ASKER CERTIFIED SOLUTION
rrz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61