JSP / Java code structure where logic is missing in the JSP file

This is a question of design and a question of good practice. How you structure your Java web development, so there is a lot of logic in the JSP file. If you use any JSP tags for structures or loops. I see a lot of code that makes logic difficult to follow due to poorly designed JSP files. And then, when you want to output to another format, such as a PDF or an XML document, you cannot do this, because all the logic is in the JSP file.

Are there any tips or tricks you use to develop Java websites.

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

There are good practices related to Java development. Many of us who have worked for a while know them. What are some good JSP development practices.

+4
source share
2 answers

The easiest way to avoid placing logic in the JSP is to simply execute all this logic before sending the request to the JSP. The only logic you need to do in JSP is the base loop (for example, to create the rows of an HTML table), evaluating conditional statements, and formatting the data.

All this can be done without using script code (Java code) in the JSP using the JSP and EL tag libraries. The most important JSTL tag library. The JSTL tag library provides most of the logic you ever need to execute in a view, although sometimes you can also use niche third-party tag libraries such as displaytag , which can reduce the amount of JSP code that needs to be written for certain tasks.

+7
source

Since you are already using Spring, you can check out Spring Webflow. I assume you are using Spring form tags, but if not, you should also check them out. With this combination, you need very little [if any] to use JSP tags in your view logic.

0
source

All Articles