Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

new line character in JSP

 
Murli Prasad
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to call a method from a java bean which calls the status variable in the JSP page.

However I need to insert the newline character in the JSP Form.

In java bean, I am using the following method:
for(int i=0 ; i < uniqueList.size() ; i++)
{
String tmp=(String)uniqueList.get(i);
temp=temp+tmp+'\n';
}
I wish to display the string in multiple lines according to the number of iterations

But when the variable is called in JSP and I use it in the following manner:
<tr><td><%= status %> </td></tr>

It prints simply as a single string in a single line.

Please help.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should set the list in the request, and loop through it in JSP, using JSTL's forEach tag.
In the loop. you can then output a <tr> tag for each iteration.

However, if it's not what you're looking for, if you want only one tr tag, you can replace

by
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65653
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remeber that the purpose of a JSP is to create an HTML document to send to the browser. And since newlines are not significant in HTML, they have no effect on the display of the page.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!