Nemetona
asked on
how to write an if statement in a .jsp page
Hi
I am trying to test for the name of the current database from a .jsp page.
When I use ="<c:out value='${dbname}'/> it displays the name of my database on the page but when I try
<c:if test="<c:out value='${dbname}'/>='mydat abasename' "> it does not work.
Can I combing the c:If test with the c: out value?
When I tried it as
<c:if test="'${dbname}'=='mydata basename'> it did not work.
Can anyone shed any light for me, please
I am trying to test for the name of the current database from a .jsp page.
When I use ="<c:out value='${dbname}'/> it displays the name of my database on the page but when I try
<c:if test="<c:out value='${dbname}'/>='mydat
Can I combing the c:If test with the c: out value?
When I tried it as
<c:if test="'${dbname}'=='mydata
Can anyone shed any light for me, please
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
put this code before if statement so that whether mydatabase value is coming or not.
<c:out value="${dbname}" />
<c:out value="${dbname}" />
ASKER
Yes, it returns mydatabase on screen.
try this;
<c:if test="${dbname}== 'mydatabase'}">
<c:if test="${dbname == 'mydatabase'}">
ASKER
No change. This code allows the second video to display but not the first one.
you mean to say its displaying only
td><iframe width="210" height="136" src="http://www.youtube.com/embed/xxxxx=0" frameborder="0" allowfullscreen></iframe>< /td>
not this one
<td>Introduction to the CCP</td>
td><iframe width="210" height="136" src="http://www.youtube.com/embed/xxxxx=0" frameborder="0" allowfullscreen></iframe><
not this one
<td>Introduction to the CCP</td>
ASKER
Currently it is displaying How to complete your profile in CCP and the video http://www.youtube.com/embed/xxxx?rel=0"
but it is not showing Introduction to the CCP and the video ="http://www.youtube.com/embed/xxxxx=0"
but it is not showing Introduction to the CCP and the video ="http://www.youtube.com/embed/xxxxx=0"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No, When I hard coded the dbname value it does not appear to be going into the if loop at all. I tried it with both eq and ne and it made no difference.
I confirmed the value of dbname by using a c:out statement after I had set the value and before the if statement. it returned value1 eq 'value1'
I confirmed the value of dbname by using a c:out statement after I had set the value and before the if statement. it returned value1 eq 'value1'
ASKER
Sorry, I realise that I made a syntax error when testing the hard coding.
When I set the dbname to value1 it does go into the loop.
When I set the dbname to value1 it does go into the loop.
ASKER
Thank you both. I realised that when I typed in the first solution I had left a space between the } and the " and that seemed to cause it to fail.
Thanks to chainuu as well for showing me how to hard code the value to test it.
Thanks to chainuu as well for showing me how to hard code the value to test it.
it worked for me
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>
<table border="0" cellspacing="1" width="80%" >
<tr>
<td width="12%"></td>
<c:set var="dbname" value="mydatabase" scope="page" />
output: <c:out value="${dbname}" />
<c:if test='${dbname eq "mydatabase"}'>
<td>Introduction to the CCP</td>
</c:if>
<td>How to complete your profile in CCP</td></tr>
<tr>
<td width="12%"></td>
<c:if test='${dbname eq "mydatabase"}'>
<td><iframe width="210" height="136" src="http://www.youtube.com/embed/xxxxx=0" frameborder="0" allowfullscreen></iframe></td>
</c:if>
your welcome .... I didnt check the EE properly thats y i didnt update ur answer .... Any how u got answer ....
ASKER
I tried the code you suggested but it did not give me the result I wished. I double checked that I could see the value of dbname when using c:out value and it was present.
I then changed the eq to ne but still did not see any result so I wonder if the problem lies in the rest of my code.
Could you run your eye over it and see if I have anything wrong? I am trying to display a single video if the user belongs to one database and two video's if the user belongs to mydatabase.
<div clsss="showvideo">
<table border="0" cellspacing="1" width="80%" >
<tr>
<td width="12%"></td>
<c:if test="${dbname eq 'mydatabase'} ">
<td>Introduction to the CCP</td>
</c:if>
<td>How to complete your profile in CCP</td></tr>
<tr>
<td width="12%"></td>
<c:if test="${dbname eq 'mydatabase'} ">
<td><iframe width="210" height="136" src="http://www.youtube.com/embed/xxxxx=0" frameborder="0" allowfullscreen></iframe><
</c:if>
<td><iframe width="210" height="136" src="http://www.youtube.com/embed/xxxx?rel=0" frameborder="0" allowfullscreen></iframe><
</tr>
</table>
</div>