Applets: getParameter() stripping carriage-returns and line-feeds????

R

rrey2279

I have an applet embedded within an HTML page that uses
getParameter(string) to accept a large string from an HTML text area.
The user can type up to 5000 characters into this text area.

My problem is that getParameter(string) is stripping the line breaks
from the text that the user enters and the applet cannot determine how
the paragraphs should be shaped.

Any ideas why this would happen and how to get around it?
I'm using JRE 1.4.2_03
 
J

John C. Bollinger

I have an applet embedded within an HTML page that uses
getParameter(string) to accept a large string from an HTML text area.
The user can type up to 5000 characters into this text area.

My problem is that getParameter(string) is stripping the line breaks
from the text that the user enters and the applet cannot determine how
the paragraphs should be shaped.

Any ideas why this would happen and how to get around it?
I'm using JRE 1.4.2_03

Your applet is not doing what you describe by itself. Applets get their
parameters from <param> elements nested inside their <applet> or
<object> tag, not from form elements. Are you perhaps submitting the
form, taking the submitted text, and putting it inside a <param> tag for
an applet on a new page? It pays to be specific, because the answer may
hinge on the details.

In this case, the most likely problem revolves around the fact that line
breaks are not distinguished from other whitespace in HTML, except
inside elements that are preformatted (which is just <pre> elements
unless you get CSS involved). If line breaks need to be interpreted as
data then you should encode them in some manner. One technique would be
to encode the whole text with a base-64 encoding. Do note, however,
that anything along these lines potentially exposes you to differences
between line termination conventions on different clients. This is not
a Java-specific issue.


John Bollinger
(e-mail address removed)
 
R

rrey2279

John said:
Your applet is not doing what you describe by itself. Applets get their
parameters from <param> elements nested inside their <applet> or
<object> tag, not from form elements. Are you perhaps submitting the
form, taking the submitted text, and putting it inside a <param> tag for
an applet on a new page? It pays to be specific, because the answer may
hinge on the details.

In this case, the most likely problem revolves around the fact that line
breaks are not distinguished from other whitespace in HTML, except
inside elements that are preformatted (which is just <pre> elements
unless you get CSS involved). If line breaks need to be interpreted as
data then you should encode them in some manner. One technique would be
to encode the whole text with a base-64 encoding. Do note, however,
that anything along these lines potentially exposes you to differences
between line termination conventions on different clients. This is not
a Java-specific issue.


John Bollinger
(e-mail address removed)


Thank you for the response. You assumed everything correctly. I am
submitting a form to another page where an applet resides.

I'm using applet <param/> tags. Something like this:

<OBJECT classid="foo">
<param name="formText" value="<% request.getParameter("formText");%> ">
</OBJECT>

I know that all of the clients are running windows2000 or XP for this
particular app.

Are you suggesting to encode the text onSubmit()? I've already tried
using Java's URLEncoder.encode() method from within the applet, but its
already to late at that point. The CR's and LF's have already been
stripped once the data is sent into the applet thru param tags.
 
J

John C. Bollinger

Thank you for the response. You assumed everything correctly. I am
submitting a form to another page where an applet resides.

I'm using applet <param/> tags. Something like this:

<OBJECT classid="foo">
<param name="formText" value="<% request.getParameter("formText");%> ">
</OBJECT>

I know that all of the clients are running windows2000 or XP for this
particular app.

Are you suggesting to encode the text onSubmit()? I've already tried
using Java's URLEncoder.encode() method from within the applet, but its
already to late at that point. The CR's and LF's have already been
stripped once the data is sent into the applet thru param tags.

I am suggesting that the _server_ should encode the form text before
writing it to the response. The URLEncoder might actually be a good
choice for that, actually, but remember to use the version of
URLEncoder.encode() that accepts a charset name argument, and be certain
that the client decodes with the same charset. This strategy will also
protect you against other problems such as accidental (or intentional,
malignant) double quotes in the submitted text.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top