tags:

views:

716

answers:

2

This is a design question and good practice question. How do you structure your Java web development such that a lot of logic is not in the JSP file. Should you use any of the JSP tags for if structures or loops. I see a lot of code where the logic is hard to follow because of poorly designed JSP files. And then when you want to output to a different format like a PDF or XML document, you can't do it because all the logic is in the JSP file.

Are there any tips or practices that you follow for Java Web development.

I am currently using a combination of Spring, Hibernate, Struts...and work with some Servlet code.

There are good practices associated with Java development. Many of us that have worked a while know them. What are some good practices for JSP development.

+6  A: 

The easiest way to avoid placing logic in JSPs is simply to perform all that logic before forwarding a request to a JSP. The only logic you should need to do in a JSP is some basic looping (e.g. for creating HTML table rows), evaluating conditional statements, and data formatting.

All of this can be done without using scriptlet code (Java code) in the JSPs by using JSP tag libraries and EL. The most important tag library is JSTL. The JSTL tag library provides most of the logic you should ever need to perform in a view, though you may occasionally also use niche 3rd party tag libraries like displaytag which can reduce the amount of JSP code you need to write for specific tasks.

Don
Exactly, that is what I was thinking.
Berlin Brown
If using WebSphere, be wary of using JSTL functions. The tags will work, but the functions may not work properly because of a bug that was fixed in 6.0 u 13. If you have an earlier version, the functions may blow up...you'll have to create tags to perform the functions.
MetroidFan2002
A: 

Since you're already using Spring you may want to check out Spring Webflow. I assume you're using Spring form tags, but if not, you should check those out as well. With this combination there should be very little need [if any] to use JSP tags in your view logic.

rich