• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with using PrintWriter inside a JSP  RSS feed

 
Sowrabha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP where i try to print a XML data.

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>"")

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.


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>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66148
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sowrabha",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Sunesh Kumar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sowrabha,

First please can you verify there is a implict object "out" in jsp.
we need not declare PrintWriter separately...

you can straight farwordly use
out.print() and out.println() methods

hope this helps...

bye
 
Sunesh Kumar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sowrabha,

PrintWriter out= response.getWriter();

First please can you verify there is a implict object "out" in jsp.
we need not declare PrintWriter separately...

you can straight farwordly use
out.print() and out.println() methods

hope this helps...

bye
 
Eduardo Dela Rosa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Although both PrintWriter and JspWriter extends java.io.Writer, they're designed to be used for specific purpose.

If your working on Servlets, use PrintWriter (from response.getWriter()).

If your working on JSP's, then use JspWriter (implicit object called *out* from pageContext.getOut() which returns javax.servlet.jsp.JspWriter).

JspWriter (out) is much preferrable to use because it uses buffering techniques designed for JSP.

Therefore, it *could be*, but not provenly, that your display has been affected by buffering. It's just a guess.

HTH.
 
kishor chandra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sourabha,
i think you are not fully aware of JSP.
it is strictly mentioned that you must use out implicit object a s in JSP SPEC.
SO hope you would get it .
thanx
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!