tags:

views:

146

answers:

3

Hi, i have two different bodies for different conditions. can i do like this....

<%
if(yes)
%>
<body onload="JavaScript:timedRefresh(120000);">
<%
}
else
{
%>
<body>
<%
}
%>

Please help me... Thanks in advance..

I want to compare my title in if condition how can i do??? currently i am doing like this:

<head>
<title>
    <tiles:getAsString name="title"/>
</title>

</head>
<%
if(%><tiles:getAsString name="title"/><%.equals("Trade Confirmation Analysis Screen")) %>
    <body onload="JavaScript:timedRefresh(120000);">
<%else
{
    %>
    <body>
    <%
}
%>

Its giving me error..Unable to compile class for JSP:

+1  A: 

YES you can use it. USE following instead.

<body <% if(yes) {%> onload="JavaScript:timedRefresh(120000);" <% } %>>
Salil
thanks.. i ll let u know of it doesnt work..
gautam
please have a look i have updated the code.. now its giving me error.
gautam
A: 

You can not do this with just HTML. In your example it looks like you're doint it with ASP and i see no reason why this shouldn't work.

Volmar
No, i am not doing this in HTML. Its in JSP..
gautam
A: 

The first one basically does this:

if (yes)
    out.println("<body onload=\"JavaScript:timedRefresh(120000);\">");
} else {
    out.println("<body>");
}

Is that syntactically valid? No, the first { is missing. You need to ensure that the Java code is syntactically valid. The second one is also syntactically invalid. You're attempting to invoke equals() on nothing.

That said, scriptlets are a poor practice. Rather use taglibs/EL. The JSTL <c:if> or the EL's ternary operator is perfectly suitable here. E.g.

<body <c:if test="${yes}">onload="JavaScript:timedRefresh(120000);"</c:if>>

or

<body ${yes ? 'onload="JavaScript:timedRefresh(120000);"' : ''}>
BalusC