• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

about if ..else in jsp

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look in the generated servlet is your best bet.
 
Why is the word "abbreviation" so long? And this ad is so short?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic