• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP compilation error due to if and else  RSS feed

 
Suresh KumarPandey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the else is giving error here
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Simple Web Application </title>
</head>
<body>
<%!
boolean b=false;;
%>

<% if (b) { %>
<jsp:forward page="forward.jsp"></jsp:forward>
<% } %>
<%
else
%>
<jsp:include page="include.jsp"></jsp:include>


</body>
</html>
 
Suresh KumarPandey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have used braces with else but then also it is giving error
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using the JSTL <c:if> pr <c:choose> tags in place of obsolete Java scriptlets. Syntax difficulties are just one of the very many reasons that Java scriptlets have been obsolete and discredited for over 12 years.
 
Mazen Mahmoud
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You should avoid using scriptlets in your JSP. Anyhow, change <% } %> <% else %> to <% } else %>. This should solve your problem.

Regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!