Meaningless Drivel is fun!*
The moose likes JSP and the fly likes JSP's and TEXTAREA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Watch "JSP New topic
Author

JSP's and TEXTAREA

Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Hi,
This may be a stupid question but I am attempting to output a TEXTAREA with the content generated by JSP code enumerating through a vector of data.
I have 2 problems,
<TEXTAREA>
JSP CODE HERE
JSP CODE HERE
</TEXTAREA>
1)
I am finding that spaces between the JSP code is
being resolved into the textarea, I know this is
valid but is there a way of stopping it as I have
to put all the jsp code on one line with no spaces. Any later reformatting of this will reintroduce the problem.
2) What do I put after each line to cause a carriage return, I've seen "%0D%0A%" but cant get this to work
TIA Graham
monica
Greenhorn

Joined: Oct 08, 2002
Posts: 2
I have the same problem as descibed on item two. Has anyone seen a solution on this problem???
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Probably the best way to handle output of something like a text area is using custom tags. If you build a custom tag which emits the start and end of the TEXTAREA element, and place one or more custom tags which generate the content, inside it you will have much finer control over whether spaces and end-of-line characters are included in the content of the text area.
If you are not comfortable with custom tags, you could write a general "helper" class to generate the whole TEXTAREA, and call your line-by-line code from it.
As for your other question What do I put after each line to cause a carriage return, I've seen "%0D%0A%" but cant get this to work
This puzzles me. Can you describe what you want to do in a bit more detail?
A sequence like "%0D" looks like a URL-encoded version of an ASCII carriage return character. You would use an encoding lkike this if you were building a URL with GET parameters which included end-of-line characters.
In a JSP, you would probably either put the end-of-line character in directly (in a text context such as a textarea), or maybe put in an HTML line-break ( <P/> or <BR/> ) in an HTML context.
Do either of these sound like what you are trying to achieve? Or have I missed the point ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi graham
here is what i understand from ur description,
u have jsp output which u want to put in textarea but u don't want the spaces that is obeyed by jsp (e.g. if u write two jsp stmts in two lines then there are two lines in output), right??
i guess that the data u have as a result is string formatted as u want to put it in textarea.
so why don't u do something like this,
<%
StringBuffer sb = new StringBuffer();
for(i=0; i < vector.size(); i++) {
sb.append((String)vector.elementAt(i));
}
%>
<textarea>
<%=sb.toString%>
</textarea>

won't this work for you?
regards
maulin
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Graham Mead:

2) What do I put after each line to cause a carriage return, I've seen "%0D%0A%" but cant get this to work
TIA Graham

well dear
what u can do is catch the ascii of carriage return i.e 13 or catch "\n" & replace it with <br> or <p>...
hope this helps
MB.
Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
I like Franks idea of creaing a custom tag.
Struts also has some custom tags that already do this....


Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
HI Regarding your 2nd query I faced a similar problem when I tried to redirect the page to another jsp page with the content of the textarea appended to the querystring.Response.encodeRedirectURL() didnt work.So i used java.net.URLEncode.encode() & it worked perfectly for me.Maybe u could try the same.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP's and TEXTAREA
 
Similar Threads
Reading a string from textarea
problem with text area tabspace
textarea cols ?
Help with values from HTML page to JSP page.
trouble with textarea