Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Total newby JSP if block question is this legal

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this block legal

in psdo code its

if(serverName = 'serverProd)
link = somethin1
else if(serverPort = 8080)
link = serverName:serverport
else
link = serverName

Thanks for any help
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if blocks did not end right is this legal

 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost, you have to do the set to the variable, you cannot declare things like "value link" in the middle of the page because that is only text (have you tried your example?) You have to set the value via <c:set tag

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks link was only a placeholder I was more interested in getting the if then else block correct
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually you have a tag that doesn't end (<c:when test="${pageContext.request.serverPort}"> ) and a </c:otherwise> that doesn't close anything (line 19)

It's also a bit weird that param.number can have value serverProd or 8080, seems somehow strange.

For only two conditions I would use c:if instead of <c:choose, check this:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that you can have as many when's as you like.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cheers I got confused by an examples if you only doing one check when if you are doing a if/else blocl

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And remember that you can nest <c:choose> tags inside <c:when> tags.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finished working product, its a choose within a choose


 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 207
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post code within code blocks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic