Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formating lines in jsp

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I print line by line in a JSP page? When I print using out.println(), it prints in the same line with the previous line.

Thanks in Advanced!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because you should be outputting HTML. What does HTML do with a newline? Ignores it.

(And why are you generating HTML with an out.println()???)
 
Nilesh Miskin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you use out.println() in a JSP? Use of scriptlets in JSP is discouraged. As far your question goes, having a look at the container generated servlet code for your JSP will clear your doubt.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below, that is my code,

I need print every book in a line, but here, it prints in the same line. What is the solution?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:That's because you should be outputting HTML. What does HTML do with a newline? Ignores it.

No, really: output HTML. How do you get a line break in HTML?
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use JSTL instead of scriptlets...

using scriptlets in your jsp pages are outdated now ....

this link may help you to convert your code using JSTL

JSTL BASICS


 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David Newton, I got that break, and vijin das, thanks a lot for that suggestion. I'm a newbie, so I'll try to catch it up! Thanks guys!
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you MUST use scriptlets (which you shouldn't), you can import classes into your JSP by using the page directive. That way, you don't have to write the fully-qualified names of all the classes. For example:
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael Angstadt...
 
Ricky Jay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't see the rest of the thread. Comment was not relevant.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a newbie, form good habits now. No java code (scriptlets) in JSPs.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:As a newbie, form good habits now. No java code (scriptlets) in JSPs.

Thanks Bear Bibeault for this suggestion, It's great! Then should I go to JSTL? Thanks in Advanced!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, your JSPs should use the JSTL and the EL in place of old-fashioned scriptlets.

If you need more power, that's where more advanced capabilities such as custom tags, tag files, and EL functions come in.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic