Reputation: 23276
When i execute the following code :
<script type="text/javascript">
function UploadMessage() {
<%! String message = null;
boolean AttemptToUploadFile = false;
%>
<%
message = (String)request.getAttribute("SuccessMessage");
if(message != null) {
%>
alert("File Successfully Uploaded !");
<% } %>
<% else if((Boolean)request.getAttribute("UploadAttempt")) { %>
alert("Unable to upload file");
<%}%>
}
I get the following error :
media/work documents/UnderTest/NetbeansCurrent/ProjectSnippets/build/generated/src/org/apache/jsp/portfolio_005fone_jsp.java:252: error: 'else' without 'if'
else if((Boolean)request.getAttribute("UploadAttempt")) {
1 error
The error says if
without else
but i have placed else
immediately after if
. Then why the error?
Upvotes: 1
Views: 499
Reputation: 2121
You haven't placed it immediatety after if
. There is %>
+ newline + <%
between it. JSP must output the newline in the generated code, so there is something like out.print("\n\t\t");
(including indention) between }
and else if
in the resulting java code.
Upvotes: 0
Reputation: 17525
Your error is in these two lines:
<% } %>
<% else if((Boolean)request.getAttribute("UploadAttempt")) { %>
In the resulting java code, they will (basically) be translated to:
}
out.append("\n");
else if(...
So you need to place the closing parentheses in the same scriptlet like this:
<% } else if((Boolean)request.getAttribute("UploadAttempt")) { %>
Upvotes: 2
Reputation: 700512
You have to put them in the same script block. Just remove the ending %>
and the beginning <%
:
<% }
else if (...
Upvotes: 6