• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write() v/s println()

 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
here is File.jsp:
<jsp:useBean id="cool" class="mytagdir.MyBean" scope="session" />
<% out.write(cool.getMarks()); %>
<% out.print(cool.getMarks()); %>
MyBean.java:
package mytagdir;
public class MyBean {
public MyBean() {
System.out.println("constructor of MyBean");
}
public int getMarks() {
return 100;
}
}
When we access the File.jsp file through the browser then it shows "d 100". I didn't get why the write method in jsp file returns the ascii value of the output of getMarks() method?
ashok.
 
Big Cat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your JSP page, "out" is instance of class JspWrite which entends from java.io.Writer. when you call out.write(int i) it uses java.io.Writer method:
write(int c)
Write a single character.
when you call out.print(int i) it uses JspWriter method:
print(int i)
Print an integer.
that is the reason you got the output of "d 100".
wish that will help.
Big Cat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic