Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP - using ${expressions} in scripts

Status
Not open for further replies.

hughesai

Technical User
Aug 1, 2002
101
0
0
GB
Apologies in advance - I'm new to JSPs and struggling with some basic issues.

My present problem is that I need to build a url. This will be of the format:

/somepage?param1=p1&param2=p2.

p1 and p2 are stored in a database rowset, lets call them ${row.p1} and ${row.p2}.

I need to create a string made up of "/somepage?param1=" ${row.p1} "&param2=" and ${row.p2}.
In a servlet this would be easy, but I can't find the correct syntax for a JSP.

I have tried building the string in a scriplet:

<% String url = "/somepage?param1=" + ${row.p1} + "&param2=" + ${row.p2}; %>

This fails to complile - the ${row.p1} syntax is not recognised - jasper error is "expected ";".

I have also tried doing this in a core tag:

<c:eek:ut value=" ${ '/somepage?param1=' + row.p1 + '&param2=' + row.p2 }">

I get no error message from the compiler or at runtime, but the page does not display.

One variation which nearly worked was:

<c:eek:ut value="/somepage?param1=${row.p1}&param2=${row.p2}"/>

This displayed the first part of the string and the value of p1, but failed to show the second half.


I would like to know what I'm doing wrong in both cases if anyone can help.
How can an expression e.g. ${row.p1} be referenced in a scriplet?
How can several expressions and strings be cocatenated within a tag?

Thanks in advance.






 
To concatenate Strings, you just need to use the + operator.

What kind of class "row.p1" is?

Cheers,

Dian
 
Thanks Dian.

row is a a recordset which I am accessing through a <sql:...> tag. p1 is a field in that reecordset.

I have already tried concatenating with + but this has not helped.
 
Can you extract the value from your recordset?

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top