Author
formating lines in jsp
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
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!
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jul 21, 2010 06:07:22
0
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
Joined: Jun 17, 2010
Posts: 44
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.
Nilesh Miskin
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
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
Joined: Sep 29, 2008
Posts: 12617
posted Jul 21, 2010 06:30:59
0
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
Joined: Jun 07, 2010
Posts: 129
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
VIJINDAS
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
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
Joined: Jun 17, 2009
Posts: 272
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:
SCJP 6 || SCWCD 5
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
Thanks Michael Angstadt...
Ricky Jay
Ranch Hand
Joined: Feb 12, 2010
Posts: 62
Didn't see the rest of the thread. Comment was not relevant.
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56169
As a newbie, form good habits now . No java code (scriptlets) in JSPs.
[Smart Questions ] [JSP FAQ ] [Books by Bear ] [Bear's FrontMan ] [About Bear ]
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
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
Joined: Jan 10, 2002
Posts: 56169
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
Joined: Nov 04, 2009
Posts: 2066
Thanks a lot.....
subject: formating lines in jsp