• Post Reply Bookmark Topic Watch Topic
  • New Topic

bad servlet/JSP organization?

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm modifying some code created by a lone contractor, and I'm wondering if his organization would be considered good. On his JSPs, he turns to servlets to get the data he needs from a database. Good, right? Well, he does it by spitting out a little HTML, then calling myBean.buildCustomerTable, where that method returns a string that he just prints out. The bean's method contains a lot of lines that look like this:

I'm new to JSP/servlets, but it seems like the architecture is supposed to avoid having servlets get involved with presentation as much as that. Am I right? And unless I'm just a whiner, it also seems to make modifying (especially adding functionality to) the code kind of annoying. I feel I have to be extra cautious about making changes. The reason I ask is because, if this is the case, then I'd like to explain to my boss that things really are kind of hairy in the code and I'm not just slow (he doesn't know Java).

A little editing to prevent blowing out the edges. - Carl
[ August 27, 2003: Message edited by: Carl Trusiak ]
 
leo blk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally I will write a servlet that contains only methods and do include a jsp page to display. It's easy if you want to change the display you just need to change the jsp page without have to recompile and restart the server. This also make code much clean and organize.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a one word answer: YES.
That is some pretty hairy code.
Good Servlet/JSP organization will always have a separation of concerns - that is, the servlet doesn't worry about HTML and the JSPs don't process any business logic.
If you need a HTML function for use in a JSP, then put it in a java utility class or define a function on that particular page.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By todays standards YES! However, it's hard to be judgemental not knowing the history of this application. Actually if this was written any time in the past 4 years, the Consultant was WAY OverPaid!
However, I remember when Java was just hitting the Server side. Companies started there own ways of handling this. My first experience was with Oracles JWEB Server. All classes called by the JWeb Server had to extend (Of all things) JWeb.class. It's was all or nothing. Your Java class had to write all the HTML.
Then Servlets came along. Hum, pretty much the same as before but, now all containers did it that way. A few brave companies started their own templating. JServ had the Servlet Tag! Now the bulk of your static ouput could reside on the jhtml page and the Servlet only had to write the dynamic stuff.
Finally JSPs came along and admittedly where quite a few steps behind some of the other Template Engines like WebMacro.
If your poor lone Consultant got caught on the edge of all this with short time lines and little time to learn the new technologies, you could easily see this as the end result.
The best way to explain it to your boss is to that it's written at the bleeding edge of Java Server side stuff and is bleeding everywhere!
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yeah,
PS : This will be difficult, time consuming and costly to maintain. Any minor chage even in style or color results in a huge large development effort. To extend or add functionality, it would be cheaper to rewrite from scratch using something like Struts and JSTL!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!