Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dumb Question -- How do you get rid of Spaces in JSP Expression FormData?

Reply
Thread Tools

Dumb Question -- How do you get rid of Spaces in JSP Expression FormData?

 
 
LB
Guest
Posts: n/a
 
      07-07-2008
I'm using an HTML form on a .jsp page which sends the following hidden
field (amoung other data fields)

<INPUT TYPE="hidden" name="realPath" value= <
%=application.getRealPath("/")%> >

application.getRealPath("/") resolves to: "C:\Documents and Settings
\HP_Administrator\My Documents\NetBeansProjects\SampleProject\build
\web"

Not sure why, but when the data is sent to next page (via either POST
or GET) the spaces do NOT flip to '+' as expected for the realPath
piece of data. All the other data entries translate correctly. The
system only sends "C:\Documents" and stops right there. (actually it
looks like "realPath=C%3A%5CDocuments" but you get the idea.)

Anybody been here before? Any hints on how to fix this?
thanks in advance,
LB
 
Reply With Quote
 
 
 
 
shakah
Guest
Posts: n/a
 
      07-07-2008
On Jul 7, 12:04*am, LB <(E-Mail Removed)> wrote:
> I'm using an HTML form on a .jsp page which sends the following hidden
> field (amoung other data fields)
>
> *<INPUT TYPE="hidden" name="realPath" value= <
> %=application.getRealPath("/")%> >
>
> application.getRealPath("/") resolves to: "C:\Documents and Settings
> \HP_Administrator\My Documents\NetBeansProjects\SampleProject\build
> \web"
>
> Not sure why, but when the data is sent to next page (via either POST
> or GET) the spaces do NOT flip to '+' as expected for the realPath
> piece of data. *All the other data entries translate correctly. *The
> system only sends "C:\Documents" and stops right there. *(actually it
> looks like "realPath=C%3A%5CDocuments" but you get the idea.)
>
> Anybody been here before? *Any hints on how to fix this?
> thanks in advance,
> LB


Are you quoting the value attribute, i.e.:
<INPUT TYPE="hidden" name="realPath" value="<
%=application.getRealPath("/")%>" >

FWIW, it can be helpful to make a regular practice of validating your
HTML
output via tools like those found at htmlhelp.com, w3c.org, the
WebDeveloper extension for Firefox, etc.
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      07-07-2008
LB wrote:
> I'm using an HTML form on a .jsp page which sends the following hidden
> field (amoung other data fields)
>
> <INPUT TYPE="hidden" name="realPath" value= <
> %=application.getRealPath("/")%> >
>
> application.getRealPath("/") resolves to: "C:\Documents and Settings
> \HP_Administrator\My Documents\NetBeansProjects\SampleProject\build
> \web"
>
> Not sure why, but when the data is sent to next page (via either POST
> or GET) the spaces do NOT flip to '+' as expected for the realPath
> piece of data. All the other data entries translate correctly. The
> system only sends "C:\Documents" and stops right there. (actually it
> looks like "realPath=C%3A%5CDocuments" but you get the idea.)
>
> Anybody been here before? Any hints on how to fix this?
> thanks in advance,
> LB

You need to make sure you put quotes around it. You should also
probably make sure you HTML or XML escape your output at some point,
you'll be sorry if you don't
The problem is that you HTML output is

<INPUT TYPE="hidden" name="realPath" value= C:\Documents and
Settings\HP_Administrator\My
Documents\NetBeansProjects\SampleProject\build\web >

Which isn't valid HTML! The web browser will see that the attribute
called "value" of your input field is "C:\Documents", and then it will
see that it has a bunch of nonsensical other attributes, such as "and",
"settings\HP_Administrator\My", etc...

BTW, View Source is a wonderful tool for seeing what is actually
generated before the browser munges it in parsing
And remember to always escape your output appropriately.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
Reply With Quote
 
LB
Guest
Posts: n/a
 
      07-08-2008
Many thanks to all for your replies. I've learned a lot today.

1)From: shakah <(E-Mail Removed)> Date: Mon, 7 Jul 2008 06:01:18
-0700 (PDT)
Are you quoting the value attribute, i.e.:
<INPUT TYPE="hidden" name="realPath" value="<
%=application.getRealPath("/")%>" >

FWIW, it can be helpful to make a regular practice of validating your
HTML output via tools like those found at htmlhelp.com, w3c.org, the
WebDeveloper extension for Firefox, etc.

LB Response: Obviously you are correct. I did leave off the
quotation marks. In fact I left them off servlets and EL Expressions
throughout my JSP document.

And yes everybody is correct about HTML validation. Haven't had to do
that in quite a while. Biggest issue here is, until I saw your
responses (particularly the one about Internet Explorer right click
View Source) I never realized how Java servlet code resolved in
HTML... I just presumed the source would appear same as JavaScript,
visible to the world in view source. I presumed that I have to use
javaBeans throughout to hide the majority of my code. Obvious that
was wrong... thanks for the hints.

Shakah, thank you!


2)From: Lew <(E-Mail Removed)> Date: Mon, 07 Jul 2008 09:25:01
-0400

Use lower-case HTML tags, so that the transition to XHTML is easier.

Use EL '${realPath}' instead of scriptlet '<%= ... %>'.
--
Lew

LB Response: Lew, thanks for your info. I didn't have a clue about
going to lower-case HTML tags. I will do that from now on in all my
code! The other hint on EL '${realPath} stuff got me to re-examine my
understanding of Expression Language (EL) nomenclature. I spent a
couple of hours today trying to refresh my memory of EL why's and go
thru some examples. I spent a lot of time digesting sites like
http://java.sun.com/developer/EJTech...04/tt0126.html. I still
haven't figured out how to translate the JSP Expression <%=... to EL $
{... expression, but I'm still working on it. I would have thought JSP
Expression <%=application.getRealPath("/")%> would map to EL
expression ${applicationScope.getRealPath} but that doesn't seem to
work. I do some more research after I complete this note.

One question: I'm doing the meat of my work within Plain Old Java
Class(POJO) JavaBean objects in this project. I'm sending the
realPath into the JavaBean class from the calling xxx.jsp file using
the <INPUT type ="hidden"... I need that pathname for file I/O. My
real question is, "Is there a way to call for the realPath from within
the javaBean class itself?"

--LB


3)From: Daniel Pitts <(E-Mail Removed)> Date:
Mon, 07 Jul 2008 07:47:57 -0700

You need to make sure you put quotes around it. You should also
probably make sure you HTML or XML escape your output at some point,
you'll be sorry if you don't
....

BTW, View Source is a wonderful tool for seeing what is actually
generated before the browser munges it in parsing
And remember to always escape your output appropriately.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

LB Response: Daniel, thanks for your feedback. I do have a
question... What do you mean by the word 'escape' in the sentence
"make sure you HTML or XML escape your output at some point". Do you
mean do an HTML source validity check on the web page?

I presume by "View Source" you are talking about Internet Explorer,
right click, View Source, and not some other fancy program, right?
Until I read your note, I didn't realize that expressions were
translated BEFORE the page was displayed. (okay, duh!) I just never
thought about it. Good idea! I agree, View, Source is a great way to
quick test expressions. Daniel, thanks for your feedback.

Again, thanks to all for the education here.
--LB

 
Reply With Quote
 
LB
Guest
Posts: n/a
 
      07-08-2008
Many thanks to all for your replies. I've learned a lot because of
your responses.

1)From: shakah <(E-Mail Removed)> Date: Mon, 7 Jul 2008 06:01:18
-0700 (PDT)
Are you quoting the value attribute, i.e.:
<INPUT TYPE="hidden" name="realPath" value="<
%=application.getRealPath("/")%>" >

FWIW, it can be helpful to make a regular practice of validating your
HTML output via tools like those found at htmlhelp.com, w3c.org, the
WebDeveloper extension for Firefox, etc.

LB Response: Obviously you are correct. I did leave off the
quotation marks. In fact I left them off servlets and EL Expressions
throughout my JSP document.

And yes everybody is correct about HTML validation. Haven't had to do
that in quite a while. Biggest issue here is, until I saw your
responses (particularly the one about Internet Explorer right click
View Source) I never realized how Java servlet code resolved in
HTML... I just presumed the source would appear same as JavaScript,
visible to the world in view source. I presumed that I have to use
javaBeans throughout to hide the majority of my code. Obvious that
was wrong... thanks for the hints.

Shakah, thank you!


2)From: Lew <(E-Mail Removed)> Date: Mon, 07 Jul 2008 09:25:01
-0400

Use lower-case HTML tags, so that the transition to XHTML is easier.

Use EL '${realPath}' instead of scriptlet '<%= ... %>'.
--
Lew

LB Response: Lew, thanks for your info. I didn't have a clue about
going to lower-case HTML tags. I will do that from now on in all my
code! The other hint on EL '${realPath} stuff got me to re-examine my
understanding of Expression Language (EL) nomenclature. I spent a
couple of hours today trying to refresh my memory of EL why's and go
thru some examples. I spent a lot of time digesting sites like
http://java.sun.com/developer/EJTech...04/tt0126.html. I still
haven't figured out how to translate the JSP Expression <%=... to EL $
{... expression, but I'm still working on it. I would have thought JSP
Expression <%=application.getRealPath("/")%> would map to EL
expression ${applicationScope.getRealPath} but that doesn't seem to
work. I do some more research after I complete this note.

One question: I'm doing the meat of my work within Plain Old Java
Class(POJO) JavaBean objects in this project. I'm sending the
realPath into the JavaBean class from the calling xxx.jsp file using
the <INPUT type ="hidden"... I need that pathname for file I/O. My
real question is, "Is there a way to call for the realPath from within
the javaBean class itself?"

--LB


3)From: Daniel Pitts <(E-Mail Removed)> Date:
Mon, 07 Jul 2008 07:47:57 -0700

You need to make sure you put quotes around it. You should also
probably make sure you HTML or XML escape your output at some point,
you'll be sorry if you don't
....

BTW, View Source is a wonderful tool for seeing what is actually
generated before the browser munges it in parsing
And remember to always escape your output appropriately.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

LB Response: Daniel, thanks for your feedback. I do have a
question... What do you mean by the word 'escape' in the sentence
"make sure you HTML or XML escape your output at some point". Do you
mean do an HTML source validity check on the web page? (Note: I did
check read your web page / blog, and I apologize, I still don't
understand your use/definition of the word 'escape'. An escape is
when I leave somewhere I don't want to be, or a key on my keyboard. I
have trouble seeing beyond that. No offense intended.)

I presume by "View Source" you are talking about Internet Explorer,
right click, View Source, and not some other fancy program, right?
Until I read your note, I didn't realize that expressions were
translated BEFORE the page was displayed. (okay, duh!) I just never
thought about it. Good idea! I agree, View, Source is a great way to
quick test expressions. Daniel, thanks for your feedback.

Again, thanks to all for the education here.
--LB

 
Reply With Quote
 
LB
Guest
Posts: n/a
 
      07-09-2008
On Jul 8, 1:35*pm, Lew <(E-Mail Removed)> wrote:

> You don't show the "get" lifestyle of accessors in EL, just the attribute, in this
> case 'realPath'.
>
> Study the tutorials.
>


Lew, I've spent a long time wading thru numerous articles including
all the Sun stuff, but nothing seems to work for me. Frankly I'm not
sure what increased efficiency I'm getting for the work, if any.

remember, <%=application.getRealPath("/")%> nets me: C:\Documents
and Settings\HP_Administrator\My Documents\NetBeansProjects
\SampleProject\build\web\ Which is exactly what I want for writing
data to a file.

I've tried :
${RealPath["/"]}
${RealPath['/']}
${realPath["/"]}
${realPath['/']}
${realPath}
${applicationScope.realPath['/']}

and those all reply with null, nada, zip. Some variations (not shown
here) crash the output. sigh. Actually big sigh. I spent a lot of
time on this, including investigating other EL / Scriplet examples to
try to figure out the correct translation from one to the other.
Note: I'm running a Tomcat local server, nearly same as final
destination server. I also have JSTL shut off, but that shouldn't make
a difference. I've learned lots about Expression Language.

Besides your references, see also: http://www.oracle.com/technology/pub...nu_jspapi.html
http://java.boot.by/wcd-guide/ch07.html

Oh, I'm pretty sure there is no way to grab the application real path
from within my javaBean class, but I believe that I did figure out an
alternative to a html syle hidden input type from a form submit. That
is to simply set the property when the bean is first called from the
JSP file... e.g.

<jsp:setProperty name="mybean" property="realPath" value="<
%=application.getRealPath("/")%>" >

As always, thank you for your responses.
--LB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM
Dumb, Dumb Vista Au79 Computer Support 4 02-11-2007 03:40 PM
Dumb, dumb dumb Qestion David Napierkowski Digital Photography 6 10-31-2004 11:14 PM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM



Advertisments