• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL and scriptlets

 
Alan Smith
Ranch Hand
Posts: 185
Firefox Browser Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have read in a few places now not to use jsp script in jsp pages. I can see why but every book I go through to learn how to do web programming always has a jsp section with scriplets. It puts me off completely even looking at it to be perfectly honest, it's horrible! JSTL seems to be the work around and far better. I am learning to use servlets now to process html forms and send the data to an output page. I use java classes as my 'backend', a servlet as a 'middle man' and JSTL to show the data on the output page. I'm just curious is this the correct way to go about it or do developers still use scriplets? I am trying to get into my head how its done in the real world. It will help me learn and understand web programming better.

In a nutshell, if you were to write an overview paragraph in a web programming book (for beginners) with the title 'How its done in the real world', what would you say?

Thanks,
Alan
 
J. Kevin Robbins
Bartender
Posts: 1745
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the real world, you'll need to understand scriptlets to support legacy code, and unfortunately, there are still companies writing scriptlet code today (like mine). I'm the heretic here because I refuse to write scriptlets.

Just over a year ago I was working at a shop that had a nightmare of scriptlet code. It was nothing for a jsp to contain over 1000 lines of scriptlet code and embedded javascript. It was a nightmare. Completely unmaintainable. I only worked there for the two months that it took me to find another job.

I've already decided that the next time I'm offered a job, I'll insist on looking at their code-base. If I see a mountain of scriptlets, I will decline the job unless it involves a project to re-design and refactor all that crap code.

You are on the right track with the MVC architecture. That's the way it should be done.
 
Harsha Ka
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More and more companies, who are into core web development have "banished" scripting. But companies which are into "quick-development" web projects sadly still use scriptlets
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any book on JSP would be incomplete without coverage of scriptlets as they are still supported by JSP.

However, as already pointed out, this should only be used when supporting legacy code. All new JSP development -- indeed, for the past 10 years -- should be free of scriptlets.

And I don't buy the "quick development" baloney. It's just as quick to do things correctly as to do them sloppily.
 
J. Kevin Robbins
Bartender
Posts: 1745
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
And I don't buy the "quick development" baloney. It's just as quick to do things correctly as to do them sloppily.


I'm certainly not defending them, but the pro-scriptlet folks at HQ reason that it's easier to upload a single jsp file, with maybe a css and js file, than to deploy servlets, POJOs, modify web.xml, etc.

What they don't seem to understand is that the time you save on initial development is going to be eaten up by maintenance, and then some. By using scriptlets, they end up with code that is untestable, can't be extended, abstracted, or re-used, and is a nightmare to modify when enhancements are requested. And I won't even address the security issue of having SQL embedded in the jsp.

There has been at least one case where I was asked to modify an existing app and it was such a mess of scriptlets that it was easier for me to completely re-write the thing using MVC rather than try to modify the existing code. By doing so, I now have an app than can be easily modified in the future.

It's like the old saying...."never enough time to do it right, but always time to do it over".

To the OP, welcome to the "real world".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic