
There are some standard practices that can be followed while writing the JSP files. The standards of writing JSP code helps to develop the application easily and effectively. It reduces the complexity and the debugging time for the JSP application. The following are the best practices, while working on JSP application:-
- Separate HTML from Java:- For small JSP files with least of logic, it seems as best to have the Java and html in the same JSP file as all available resources and dependencies are in the same file. As the JSP's go on to higher complexity, this approach fails as the code becomes
complex and less readable and hard to understand. - Place business logic in JavaBeans:- We must write our business logic in JavaBeans as the code will be reused anywhere in the application. Also if any logical change occurs during the development so it requires to change only at one place and hence avoiding rework everywhere.
- Factor general behavior out of custom tag handler classes:- If we are using custom tags then we must tend to write the common code in a Java file separately instead of writing inside the customTagHandler. Because Handler classes are not readily used like ordinary Java utility classes rather Handler classes can access the utility classes easily.
- Favor HTML in Java handler classes over Java in JSPs:- Sometimes cleanly separating HTML, JSP tags, and HTML-like custom tags from Java requires unnecessarily convoluted code. In these cases, you either include Java scriptlets and expressions in the JSP or put some HTML code in the Java tag handler class.
- Use an appropriate inclusion mechanism: - The JSP is a combination of the tags and the Java code. It is very difficult to maintain the two types of code in a single file. JSP gives us the flexibility to create the multiple JSP pages and then call those JSP pages into the complex page wherever required.
- Use a JSP template mechanism:- Using templates is the best approach when we can see the total structural changes in the look and feel of the page. It is not a good way to change each and every JSP page for the html changes, rather we will define the layout of the page in a JSP and will use the templates mechanism to import the contents of different portions from different JSP's through templates. So, when you want to change the layout, you need to modify only one template file rather making changes in all pages.
- Use stylesheets:- We must use CSS to give the styles to different components across the site, providing same CSS styles to similar kind of components. If we want to change the look of a particular type of component throughout the website, we are required to change one style only and it will be reflected everywhere.
Jsp Discussion
- - How to rip a DVD fast?
- - I want good jsp tutorials
- - Two forms in one JSP
- - PASS VARIABLES BETWEEN 2
- - Table data




