• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

\n doesnt works

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to use "\n" line but it doesnt works. Any idea, please?

 
Stephan van Hulst
Bartender
Posts: 6320
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless. TellTheDetails.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesnt split the line in too. The behaviour of the app is totally normal and no errors are shown. It just doesnt change anything and also it is not shown when the app is run
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you displaying the string? In the Windows console or a shell window, or a Swing or JavaFX GUI, on an HTML page or somewhere else?

That matters a lot for your question.
 
Stephan van Hulst
Bartender
Posts: 6320
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example of what Jesper is talking about: HTML ignores newlines.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside a Servlet I suppose that when it is like this it cant read the special caracters

 
Tim Holloway
Saloon Keeper
Posts: 18302
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you define "split the line in two"? All you've done is create a String in your sample code. You're not doing anything that would show whether or not "\n" "worked". Control characters do different things in different environments.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a break line for formatting purposes
 
Stephan van Hulst
Bartender
Posts: 6320
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What we're trying to tell you is that you need to tell us what you're using to view the String. You still haven't told us whether you're outputting it to a terminal, displaying it on an HTML page, using it in a Swing GUI or other.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chrome browser
 
Stephan van Hulst
Bartender
Posts: 6320
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you mean as an HTML page, and not a text file or something...

This is not an issue with Java. HTML doesn't use newlines to break inline content. You need to use paragraphs (<p>) or line beaks (<br>).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this line is ending up in HTML, it has already been stated that HTML ignores whitespace including new lines. TO format HTML you need to use HTML and CSS, not special characters that HTML ignores.

I've moved this to the Servlets forum where it should have been originally posted.
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it works

ex = "Over " + requestsInFile + " users the time per request is over " + loadRequestTime + "<p></p>"+"


Thanks
 
Stephan van Hulst
Bartender
Posts: 6320
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're grasping at straws. Please take your time to learn HTML.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a horrible way to do it! Bear is sad.

Figure out how to use HTML to do what you want, and then, and only then, generate that text.

P.S. Why generating markup in a servlet rather that forwarding to a JSP to create the view?
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to do it in the Servlet instead that in the jsp, which would be no confusing. More than learn HTML I think I need to sort out how to do it from the Servlet in the rigth way for this specific case, thats the point.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear what you are doing from the servlet. But regardless, you should be creating HTML that's well-formed and conventional. Using an empty P tag to emulate a new line is not conventional or good practice.

Think of how you might add this text to the HTML if you were hardcoding it into the page. How would you format the HTML?
 
Ron McLeod
Bartender
Pie
Posts: 963
59
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:That's a horrible way to do it! Bear is sad.

I want that on a tee shirt

 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Now it works

ex = "Over " + requestsInFile + " users the time per request is over " + loadRequestTime + "<p></p>"+"


Thanks


Wow that's a terrible "solution".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic