Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

about if ..else in jsp  RSS feed

 
tong yuxin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rencently i just try to write some simple code of jsp. and i think i am stuck here. please help!!

code 1;
<%
String a= request.getParameter("cer");
if(a.equals("A"))
out.println("A");
else
out.println("B");
%>
thats fine. but when i use <%=%>

code2
<% String a= request.getParameter("cer");
if(a.equals("A"))%>
<%="A" %>
<%else %>
<%="B" %>
the complier throw a exception. So, why and where i made mistakes?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .

Also, always post the text of the exception. Otherwise, we're just guessing.

And finally, why are you putting Java code in the JSP still? You should be using the JSTL and EL in place of scriptlets at this point.
[ October 06, 2008: Message edited by: Bear Bibeault ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tong yuxin:

code2
<% String a= request.getParameter("cer");
if(a.equals("A"))%>
<%="A" %>
<%else %>
<%="B" %>
the complier throw a exception. So, why and where i made mistakes?


use { and } properly

for example


more over can you put like this in your java file
-----------------------
if(true)
else
----------------------

compilar will understand the jsp like above . because <%= %> it is an expression (request time)
[ October 07, 2008: Message edited by: seetharaman venkatasamy ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the generated servlet is your best bet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!