richardsimnett
asked on
How do I get variables to be available outside of <% %>?
Hello,
Im new to JSP trying to figure some things out. How do I get variables that I set in code blocks <% %>, to be usable on a regular page? See my example below: I set the campaignid,listid,and userid values based on the querystring... it outputs fine in the block, but the variables arent avaialbe to the rest of the page?
<!---- first split apart the query string ----->
<%
String[] work = request.getQueryString().s plit("_");
if (work.length == 3)
{
String campaignid = work[0];
String listid = work[1];
String userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid);
}
%>
CampaignID: ${campaignid}<br>
ListID: ${listid}<br>
UserID: ${userid}<br><br>
Thanks,
Rick
Im new to JSP trying to figure some things out. How do I get variables that I set in code blocks <% %>, to be usable on a regular page? See my example below: I set the campaignid,listid,and userid values based on the querystring... it outputs fine in the block, but the variables arent avaialbe to the rest of the page?
<!---- first split apart the query string ----->
<%
String[] work = request.getQueryString().s
if (work.length == 3)
{
String campaignid = work[0];
String listid = work[1];
String userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid);
}
%>
CampaignID: ${campaignid}<br>
ListID: ${listid}<br>
UserID: ${userid}<br><br>
Thanks,
Rick
String[] work = request.getQueryString().s plit("_");
String campaignid = "";
String listid = "";
String userid = "";
if (work.length == 3)
{
campaignid = work[0];
listid = work[1];
userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid);
}
String campaignid = "";
String listid = "";
String userid = "";
if (work.length == 3)
{
campaignid = work[0];
listid = work[1];
userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid);
}
ASKER
Tried both out guys. Neither worked... still dont get any output from the ${campaignid} tokens outside of the <% %>.
Thanks,
Rick
Thanks,
Rick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And also are you sure work.length is == 3?
If not, then the value will be blank and you won't see anything.
hongjun
If not, then the value will be blank and you won't see anything.
hongjun
ASKER
Here is what I am getting...
The Code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!---- first split apart the query string ----->
<%
String campaignid = "";
String listid = "";
String userid ="";
String[] work = request.getQueryString().s plit("_");
if (work.length == 3)
{
campaignid = work[0];
listid = work[1];
userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid + "<br>");
}
%>
CampaignID: <%= campaignid %><br>
CampaignID: ${campaignid}<br>
The output:
1 | 1 | 1000
CampaignID: 1
CampaignID:
Why does this work for the first <%= %> but not for ${campaignid}? it makes no sense.
Thanks,
Rick
The Code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!---- first split apart the query string ----->
<%
String campaignid = "";
String listid = "";
String userid ="";
String[] work = request.getQueryString().s
if (work.length == 3)
{
campaignid = work[0];
listid = work[1];
userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid + "<br>");
}
%>
CampaignID: <%= campaignid %><br>
CampaignID: ${campaignid}<br>
The output:
1 | 1 | 1000
CampaignID: 1
CampaignID:
Why does this work for the first <%= %> but not for ${campaignid}? it makes no sense.
Thanks,
Rick
means EL isn't working
ASKER
objects,
any suggestions on how to get that to work.... it works in other places.. I have ${2+2} to test it out and that works....
Thanks,
Rick
any suggestions on how to get that to work.... it works in other places.. I have ${2+2} to test it out and that works....
Thanks,
Rick
Actually I take that back, think its a scope issue instead.
el cannot see local vars, only session/request vars. If you really want to use el, then try adding values to request scope.
el cannot see local vars, only session/request vars. If you really want to use el, then try adding values to request scope.
<!---- first split apart the query string ----->
<%
String[] work = request.getQueryString().s
String campaignid = "", listid = "", userid = "";
if (work.length == 3)
{
campaignid = work[0];
listid = work[1];
userid = work[2];
out.println(campaignid + " | " + listid + " | " + userid);
}
%>