File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Carriage Returns in Request Dispatcher attribute. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Carriage Returns in Request Dispatcher attribute." Watch "Carriage Returns in Request Dispatcher attribute." New topic

Carriage Returns in Request Dispatcher attribute.

Hazel Sisson

Joined: Feb 12, 2002
Posts: 17
Hi guys,
I'm not sure if this in the right forum, but I'm sure the sheriffs will move it if it's not!
I'm sending a string (s8) to a JSP using RequestDispatcher. What I want to do is put some carriage returns into the string, along with elements from entries[n]. This is how I tried at first:
for (int n = 0; n < NR_OF_PARAMS; n++)
if (entries[n] == "ERROR")
final Character ocChar = new Character((char)10);
final String svENTER = new String(ocChar.toString());
String s8 = s8.concat(svENTER + labels[n]);
entries[n] = "";
This displays the string with the correct elements from entries[n] added on, but it's all on one line. I have also tried putting \n in place of svENTER but that didn't work either!
Any ideas?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If you are displaying it on an HTML (or JSP)page, then you need to use <br> tags, not java \n characters.

If you do a 'view source' on the page, you'll see that the \n worked, but of course a browser ignores them as 'whitespace', and only an HTML <br> will cause the output to do a 'new line'
[ April 04, 2002: Message edited by: Mike Curwen ]
I agree. Here's the link:
subject: Carriage Returns in Request Dispatcher attribute.
It's not a secret anymore!