• Post Reply Bookmark Topic Watch Topic
  • New Topic

else statement not working in my jsp page

 
pavan manthan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am getting the following error
" Syntax error on token "else", delete this token"

when i run my jsp page. the piece of code from my jsp page is

<td><%String str=""; %>
<%str=(String)request.getAttribute("firstname"); %>
<%if(str==null){ %>

User First Name : <input type="text" name ="firstname" value="">
<%} %>
<%else { %>
User First Name : <input type="text" name ="firstname" value=<%=str %>>

<%} %>

please reply asap.
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pavan mantra:
please reply asap.

Please read this for information on why this isn't a good idea.
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pavan mantra:
User First Name : <input type="text" name ="firstname" value=<%=str %>>

<%} %>




The error you get is due to the line heghlighted. Use quotes for "value".
And please while posting use UBB code.

Thank you.
[ December 21, 2008: Message edited by: Sudipto Shekhar ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be using Scriptlets. Use EL. That whole terrible piece of code can just be replaced by

[ December 21, 2008: Message edited by: Bauke Scholtz ]
 
Venki Ananth
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please reply asap.


I guess it would help!

 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use in this way :
<%if(str.equals(""){%>
coding...
<%}else{%>
coding...
<%}%>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!