• Post Reply Bookmark Topic Watch Topic
  • New Topic

long JSP code nightmare

 
Eli Daum
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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 -->
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!