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

Discussion in 'Java' started by LB, Jul 7, 2008.

  1. LB

    LB Guest

    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
     
    LB, Jul 7, 2008
    #1
    1. Advertising

  2. LB

    shakah Guest

    Re: Dumb Question -- How do you get rid of Spaces in JSP ExpressionForm Data?

    On Jul 7, 12:04 am, 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


    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.
     
    shakah, Jul 7, 2008
    #2
    1. Advertising

  3. LB

    Daniel Pitts Guest

    Re: Dumb Question -- How do you get rid of Spaces in JSP ExpressionForm Data?

    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/>
     
    Daniel Pitts, Jul 7, 2008
    #3
  4. LB

    LB Guest

    Re: Dumb Question -- How do you get rid of Spaces in JSP ExpressionForm Data?

    Many thanks to all for your replies. I've learned a lot today.

    1)From: shakah <> 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 <> 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/EJTechTips/2004/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 <> 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
     
    LB, Jul 8, 2008
    #4
  5. LB

    LB Guest

    Re: Dumb Question -- How do you get rid of Spaces in JSP ExpressionForm Data?

    Many thanks to all for your replies. I've learned a lot because of
    your responses.

    1)From: shakah <> 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 <> 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/EJTechTips/2004/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 <> 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
     
    LB, Jul 8, 2008
    #5
  6. LB

    LB Guest

    Re: Dumb Question -- How do you get rid of Spaces in JSP ExpressionForm Data?

    On Jul 8, 1:35 pm, Lew <> 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/articles/cioroianu_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
     
    LB, Jul 9, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    7
    Views:
    5,843
    Steve
    Sep 18, 2005
  2. ucfcpegirl06

    Getting Rid of Trailing white spaces

    ucfcpegirl06, Jul 22, 2005, in forum: C++
    Replies:
    4
    Views:
    444
    ucfcpegirl06
    Jul 23, 2005
  3. Ramon F Herrera

    How would you get rid of lagging zeros?

    Ramon F Herrera, Aug 16, 2010, in forum: Java
    Replies:
    10
    Views:
    662
  4. Jerry C.
    Replies:
    8
    Views:
    263
    Uri Guttman
    Nov 23, 2003
  5. When You Need to Tell Someone

    I'm dumb, you're not... can you help me?

    When You Need to Tell Someone, Jun 13, 2008, in forum: Javascript
    Replies:
    2
    Views:
    129
    Stevo
    Jun 13, 2008
Loading...

Share This Page