• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

long JSP code nightmare

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to simplify long jsp code, to ease the job of having long nested if statements and html code in between. I am losing track and my HTML code is getting messed up
HELP!
 
Sheriff
Posts: 67746
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
Is the code in the JSP there in order to format the display? Or is it there to perform processing and/or business logic?
If the latter, your page could be a 'poster child' for urging people to consider the Model 2 pattern. In this pattern (skip to end if you've heard all this before), the URL hits a servlet (not the JSP), performs whatever non-display processing is necessary to satisfy the request, then forwards on to the JSP for display (perhaps tacking necessary data structures onto the request for retrieval by the JSP). This keeps your JSP focused on the display, and not complicated by misplaced non-display logic.
If you have already adopted Model 2, but your display design is so complicated that it requires vastly complex on-page Java to sort out, investigate the use of custom tags to factor the logic out of the page.
hth,
bear
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If its only formatting display, think of splitting the JSP page into fragments and including them in the main file.
This way u have a modularised page to maintain
<!-- main.jsp -->
..
..
..
if(condition)
{
<%@ include file="foo.jspf"%>
}
else
{
<%@ include file="bar.jspf"%>
}
..
<!-- end of main.jsp -->
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Long loops and conditionals also call for custom tags.
Used in combination with includes you can make your pages a lot easier to maintain.
 
reply
    Bookmark Topic Watch Topic
  • New Topic