Java code in JSP

Because it makes it difficult to read/debug especially when something goes wrong. The availabily of JSTL has made it a whole lot easier to achieve the same thing.

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley

Jason Cohen

Smart Bear Support
Greenhorn

Posts: 6

posted 8 years ago

Debugging isn't too hard with modern IDE's that link up errors with line numbers etc..

The real reason is that it breaks the separation between "view" logic and "application" logic.

Specifically, the "view" is how the user sees information: Styles, text, layout, art, pop-ups, etc.. This is stuff that can change easily, and does change often especially at the start of an application's life. These are things that non-programmers often have a finger in -- tech writers for the text, designers for the art, translators for the text.

In contrast, application logic is how things actually work: talking to the database, parsing out the "first" and "last" name out of a single "full name" field, validating input, processing data. These are things that non-programmers will not have a place in. This is where most of the bugs come from and ALL of the hard bugs.

Furthermore, application logic should come with lots of unit tests. View code can be hard (sometimes impossible or not worth the effort) to test.

There are more differences, but just as with object-oriented programming it's useful to separate layers, these are two layers that should be separate. So think of JSP as "just display stuff" and the rest as "just application logic" and your application will be better organized.