Blackslash combined with ${...}

T

Tim Slattery

I'm trying to print out two values separated by a backslash on my
webpage. So I start with this:

${bean.firstval}\${bean.secondval}

Apparently the \ escapes the $, because I get:

BOS${bean.secondval}

So I tried a double backslash, so that the first would escape the
second:

${bean.firstval}\\${bean.secondval}

And I got this:

BOS\${bean.secondval}

Apparently the first was interpreted as a constant, and the second as
an escape for the $. The closest I've come is to put a space before
the second $:

${bean.firstval}\ ${bean.secondval}

Which gives:

BOS\ JBLow

But that space shouldn't be there. Is there a way to get the backslash
without the space?
 
L

Lew

Tim said:
I'm trying to print out two values separated by a backslash on my
webpage. So I start with this:

${bean.firstval}\${bean.secondval}

Apparently the \ escapes the $, because I get:

BOS${bean.secondval}

So I tried a double backslash, so that the first would escape the
second:

${bean.firstval}\\${bean.secondval}

And I got this:

BOS\${bean.secondval}

Apparently the first was interpreted as a constant, and the second as
an escape for the $. The closest I've come is to put a space before
the second $:

${bean.firstval}\ ${bean.secondval}

Which gives:

BOS\ JBLow

But that space shouldn't be there. Is there a way to get the backslash
without the space?

Yes.

And when you provide the context of the write (is it in Java? EL? JSP?
[X]HTML directly? embedded in a String constant? a variable?) we can tell
you how.
 
T

Tim Slattery

Lew said:
Tim said:
I'm trying to print out two values separated by a backslash on my
webpage. So I start with this:

${bean.firstval}\${bean.secondval}

Apparently the \ escapes the $, because I get:

BOS${bean.secondval}

So I tried a double backslash, so that the first would escape the
second:

${bean.firstval}\\${bean.secondval}

And I got this:

BOS\${bean.secondval}

Apparently the first was interpreted as a constant, and the second as
an escape for the $. The closest I've come is to put a space before
the second $:

${bean.firstval}\ ${bean.secondval}

Which gives:

BOS\ JBLow

But that space shouldn't be there. Is there a way to get the backslash
without the space?

Yes.

And when you provide the context of the write (is it in Java? EL? JSP?
[X]HTML directly? embedded in a String constant? a variable?) we can tell
you how.

It's in a JSP page. The expressions are EL.
 
L

Lew

Lew said:
And when you provide the context of the write (is it in Java?  EL?  JSP?
[X]HTML directly?  embedded in a String constant?  a variable?) we can tell
you how.

Tim said:
It's in a JSP page. The expressions are EL.

Would it kill you to show actual code? How are we supposed to know
where the quote marks are, what sorts of tags, if any, surround these
expressions, and all that stuff that is relevant to backslash
escaping?

In any event, I'm guessing you need to double the backslashes:

<c:howItShouldBeDone value="${bean.firstval}\\\\${bean.secondval}" />

As I mentioned earlier, without knowing the context it's hard to be
sure. Try the doubled backslashes and let us know if that works.

The quality of answers you get is strongly influenced by the quality
of the information you provide.
 
T

Tim Slattery

Lew said:
Lew said:
And when you provide the context of the write (is it in Java?  EL?  JSP?
[X]HTML directly?  embedded in a String constant?  a variable?) we can tell
you how.

Tim said:
It's in a JSP page. The expressions are EL.

Would it kill you to show actual code? How are we supposed to know
where the quote marks are, what sorts of tags, if any, surround these
expressions, and all that stuff that is relevant to backslash
escaping?

In any event, I'm guessing you need to double the backslashes:

<c:howItShouldBeDone value="${bean.firstval}\\\\${bean.secondval}" />

That doesn't work.

As I said, its a JSP page. I'm using EL expressions, I want to display
one, followed by a backslash (\) followed by another. No spaces.

Here's an example: ListBean is a bean that's accessible from the JSP
page, values from it are used elsewhere on the page.

When the "env" property is "D", this line:
${ListBean.env}\\\\${ListBean.database}\\\\${ListBean.table}<br/>

yields

D\\\${ListBean.database}\\\${ListBean.table}

One backslash disappears, and the second and third EL expressions
don't resolve. Dropping the number of backslashes keeps doing the same
thing: three backslashes result in two, with the second and third EL
expressions not resolving. Two result in one, second and third EL
expressions not resolving. When I use only one backslash

${ListBean.env}\${ListBean.database}\${ListBean.table}<br/>

I still get a single backslash, and the second and third EL
expressions don't resolve:

D\${ListBean.database}\${ListBean.table}

So the \ seems to escape the $ right behind it, and disappear - except
when there's only one \, when it escapes the $ and stays visible. And
I can't find anyway to escape the \, that is tell the processor that
it's a character to be displayed and not an escape character.
 
L

Lew

Lew said:
Lew said:
And when you provide the context of the write (is it in Java?  EL?  JSP?
[X]HTML directly?  embedded in a String constant?  a variable?) we can tell
you how.
Would it kill you to show actual code?  How are we supposed to know
where the quote marks are, what sorts of tags, if any, surround these
expressions, and all that stuff that is relevant to backslash
escaping?
In any event, I'm guessing you need to double the backslashes:
<c:howItShouldBeDone value="${bean.firstval}\\\\${bean.secondval}" />

That doesn't work.

As I said, its a JSP page. I'm using EL expressions, I want to display
one, followed by a backslash (\) followed by another. No spaces.

Here's an example: ListBean is a bean that's accessible from the JSP
page, values from it are used elsewhere on the page.

When the "env" property is "D", this line:
${ListBean.env}\\\\${ListBean.database}\\\\${ListBean.table}<br/>

yields

D\\\${ListBean.database}\\\${ListBean.table}

<c:eek:ut value="${ListBean.env}"
/>\\<c:eek:ut value="${ListBean.database}"
/>\\<c:eek:ut value="${ListBean.table}"
/><br>
?

I remain puzzled by your unwillingness to share the context of the
expressions.
 
T

Tim Slattery

<c:eek:ut value="${ListBean.env}"
/>\\<c:eek:ut value="${ListBean.database}"
/>\\<c:eek:ut value="${ListBean.table}"
/><br>
?

I remain puzzled by your unwillingness to share the context of the
expressions.

I remain puzzled as to what you want.

I found one way around:
${ListBean.env}${"\\"}${ListBean.database}${"\\"}${ListBean.table}<br/>

Seems rather baroque, but it works....
 
L

Lew

Tim said:
I remain puzzled as to what you want.

You never showed the context for your EL expressions, despite
repeated, explicit detailed requests for that information. One could
not tell initially if your expressions are inside a tag attribute or
in the content part of the JSP, for example. Upon repeated requests
for context, all you told is that it was in a JSP - no detail
whatsoever. You deprive those who would help you of necessary data to
help you.

Here's what you need to provide, in future:

<http://sscce.org/>

Tim said:
I found one way around:
${ListBean.env}${"\\"}${ListBean.database}${"\\"}${ListBean.table}<br/>

That's pretty similar to what I suggested. Is this XHTML? (I know, I
asked that already, but you didn't answer.) If not, the slash in the
<br> tag is an error. I infer without your direct response that the
snippet is from the content part of the JSP.

Remember:

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>

<http://sscce.org/>
 
A

Arved Sandstrom

Tim said:
I remain puzzled as to what you want.

I found one way around:
${ListBean.env}${"\\"}${ListBean.database}${"\\"}${ListBean.table}<br/>

Seems rather baroque, but it works....
Maybe it's just me, but what's wrong with tossing in \

It's a fixed symbol - let the browser take care of it.

AHS
 
D

Daniel Pitts

Tim said:
I'm trying to print out two values separated by a backslash on my
webpage. So I start with this:

${bean.firstval}\${bean.secondval}

Apparently the \ escapes the $, because I get:

BOS${bean.secondval}

So I tried a double backslash, so that the first would escape the
second:

${bean.firstval}\\${bean.secondval}

And I got this:

BOS\${bean.secondval}

Apparently the first was interpreted as a constant, and the second as
an escape for the $. The closest I've come is to put a space before
the second $:

${bean.firstval}\ ${bean.secondval}

Which gives:

BOS\ JBLow

But that space shouldn't be there. Is there a way to get the backslash
without the space?
Have you tried "${bean.firstval}${'\\'}${bean.secondval}" ?
 
L

Lew

Tim said:
IMHO, that's exactly what I was doing!

Well, your example was short, but neither complete nor compilable nor really
much of an example. I was not able to compile "It's in a JSP page" - both
Tomcat and Java have trouble with that syntax.

Compilability is not a matter of your or anyone else's "HO" - it's objectively
verifiable by whether the example compiles. Yours did not.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top