Remember that old college wisdom? Well – mixing markup, styles and logic will give you bad one for sure. Here are some things you should always exercise when writing your JSP
- It’s already awful because of HTML/JSP special syntax mix. Do not place more than a single line of JS in that code – keep it in external, linked JS file, such code has no business to be directly in JSP.
- JS event handling. If you are putting JS code into tag attributes (e.g. <input onclick="doSomething()"/>) then you still living in XX century. Especially if you are using jQuery. All your events should be defined in JS code and be triggered within document.onload event
$(function() { // put all your jQuery goodness in here. } )
- Laying out pages with table except when you are displaying actual tabular data is a lazy habit. That’s what CSS is for. Takes time to learn but makes your pages faster and less clattered with unnecessary markup. In my mind – nested tables are worth than nested for-loops
- Avoid putting Java code into your JSP. If you have more than one line you need to have method in your Java code. Matter of fact – using plain JSP should be avoided and XHTML should be used instead
- Do not use color names in your styles e.g. <tr style="background-color: PeachPuff"> use color codes (#FFDAB9 ) And that’s beside the point that you should avoid peppering your markup with inline CSS
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.