Re: save control characters in a session object

From: Collin VanDyck (thehoppocket_at_yahoo.com)
Date: 02/23/04


Date: Mon, 23 Feb 2004 19:58:45 GMT


> I want to make a little preview before sending the information to the
> database. The text should be shown the same way the user entered into
> the form.
> (jsp)
> String ueberschrift = null, untUeber = null, text = null;
> java.util.HashMap hm = (java.util.HashMap)
> session.getAttribute("articleText");
> ueberschrift = (String) hm.get("ueberschrift");
> untUeber = (String) hm.get("untUeber");
> text = (String) hm.get("text");
>
> Not the best way I guess, but I'm not that experienced in
> Servlet programming yet.

Ah, so in creating the preview for the user, your newlines are getting
"deleted" in the page? In other words, the text all runs together?

If in your JSP you are showing the fields like this:

<p>
field one: <%= ueberschrift %>
field two: <%= untUeber %>
...
</p>

Then the HTML page this produces will not care about any newlines in your
strings. One way to get around the newline problem would be to, when you
are displaying the strings, replace all "\n" characters with "<br/>". This
will create the newlines for you in HTML.

A better solution might be to wrap your formatted text with <pre>...</pre>
tags. This attempts to preserve formatting as much as possible when
displayed in the browser.

-Collin



Relevant Pages

  • Re: CGI.pm and lost carriage returns
    ... input with tags instead of newlines, and nothing more: ... when displaying text in a browser. ... But the input was *NOT* meant to be HTML in the first place, ... designer wants user newlines to be retained in formatting. ...
    (comp.lang.perl.misc)
  • Re: simple jsp question (out.println)
    ... Since your subject line mentions JSP (btw, it'd be a good idea to ... The println statement is, indeed, writing newlines. ... is that they aren't significant in HTML. ... Source" from your web browser when you test the page. ...
    (comp.lang.java.help)
  • Re: Buffered socket I/O with sysread-style blocking?
    ... You should get a zero return from sysread if it is interrupted. ... While most HTML pages ... count on newlines being in logical places. ... I would use sysread and buffer up the data received until the HTML page ...
    (comp.lang.perl.misc)
  • Re: Server related problem
    ... The HTML part of the script is for an, unactivated, option ... You are outputting HTML. ... ignore newlines in HTML source data. ...
    (perl.beginners)
  • Re: Server related problem
    ... You are outputting HTML. ... you are putting a newline into your HTML, but browsers completely ... ignore newlines in HTML source data. ...
    (perl.beginners)