• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display a string on new line in java class?  RSS feed

 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have written a string in java class and I want to display it but the second line should start from new line
and I have used \n and <br> but it is not working

this is the string ;;

String msg = "Transaction error\nReference number for enquiry.
Please help me

Thanks
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Few more details might be helpful to investigate the issue. Like how and where are you displaying the string, simply on the console or it's a GUI based application or something else.
 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , It is a web based application and text is written inside Booking.java class and I want to display the GUI
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is understandable so far is you are rendering the output to web client i.e the content being rendered is html. What is going wrong with <br>? What output does it show in the web page?
 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I use <br> tag it gets diplayed on the GUI like this

Transaction error<br>Reference number for enquiry.

i.e. <br> is also shown in the string and when I use \n ,it just displays the sting like this

Transaction errorReference number for enquiry.

but does not go on new line
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still can't tell if the "GUI" is or is not a web page. It sounds as if it might not be...?
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or might be content type is an issue? Are you using any servlet/jsp to render the output?
 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am using jsp for rendering the output the string that is used in java class, I have stored that in form bean and I get that form bean variable on jsp and display the output
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarita,

Could you please show some parts of your code, i.e. the bean class and the jsp.
 
Philip Thamaravelil
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For HTML, it's not necessary to set the content type; it's the default. (Doesn't hurt to set it though, as long as it's correct.)

It's more likely that the string is being escaped on the JSP (likely by a struts action) so that the embedded HTML is being rendered as escaped text.
 
abida khatoon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are writing it in java class , <br> tag would appear as though..!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!