Sam Newman's site, a Consultant at ThoughtWorks

I have long since come to the conclusion that JSP pages are evil. Not just bad, oh no. Nothing which can result in such unmaintainable crufty code can be considered merely bad – only evil will suffice. This opinion has been reinforced over the last few days, and this single gem stands out.
I was using a struts logic tag (asshats, I have no choice in this – the first person to tell me to use webwork instead is getting eaten by rats) to assert a boolean condition. It looked a little something like this:

  I hate JSP

For some reason even if @boolProperty@ returned @false@, “I hate JSP” was still being printed out. It being late in the day (and a Monday) I was slow to spot the closing @/@ on what I took to be an opening @logic:equal@. Despite the fact that I had a closing @logic:equal@, no parse error was thrown. Apart from the fact that a @logic:equal@ tag is of no use to man nor beast without a body (and therefore a validation error should of been thrown by Evil Struts) I would of expected the JSP compiler to notice an extra closing @logic:equal@. Of course assumptions are a dangerous thing when it comes to JSP…

13 Responses to “JSP + Struts = one bad day”

  1. Jason Barker

    This is merely a plain user error.

    1. Do yourself a favor, use an IDE. What do you use to code?
    2. If you don’t like struts-logic tag, use JSTL. (struts-logic exists way way before JSTL, it had its days, not anymore).
    3. If you precompile your JSP, this error will be noticeable. What do you use to precompile the JSP?
    4. Blaming this on JSP and Struts is simply ridiculuous. Your error will occur on any code with such tag.

  2. Sam Newman

    To answer your questions in order:

    * I use IDEA 4. It showed no error
    * I dislike the logic tag. I cannot use the JSTL due to server restrictions. The logic tag has no business being a non-body tag in anycase – this should of been reported as an error
    * I fail to see how precompilation would of picked this error up
    * I blame it on struts because the @logic:equal@ tag seems to think not having a body is valid (when it in fact makes the tag itself pointless) and JSP because the parser sould of picked up an errant closing @logic:equal@.

  3. Andreas Mecky

    I have to agree 100%. JSP are evil but struts is even worse. These struts tags must be written by idiots.
    Wherever I can I will use velocity because you CANNOT
    put code in your templates.
    Oh, and writing your own jsp tags can be painfull. Mostly because of this damn Jasper. Another jakarta
    project that is crap. If you have an error in your
    custom tags then you are doomed since Jasper just
    swallows the exception.

  4. Jason Barker

    – I use Eclipse with Lomboz plugin, it picks up the non-well formed tag. I fail to see how such error could pass the coder’s attention, specially the ones who use IDEs.
    – What do you mean by server restriction?
    – I precompile with weblogic and it gives me compilation error when the servlet (from the jsp) is compiled. What do you use? (out of curiousity).
    – I encourage you to post it to struts mailing list, who knows you might be enlightened (or not :)). Even though I agree logic tag should no longer be used.

    Are you restricted to using Jasper? If you think it’s crap, why use that crap?

    Anyway, it just baffles me that such a simple user error drag people to blame/complain about 1) struts, 2) jsp, 3) jasper.
    If you have a simple html error like that, even simple html won’t work.

  5. Jason Barker

    Sorry, typo
    If you have an error like that, even simple html won’t work.

  6. Sam Newman

    My server restriction is that I’m coding for a websphere version which cannot use the JSTL (ealier version of the servlet API) – not much I can do about that. For development purposes I’m using Tomcat (which uses Jasper internally of course) which reports no error.

    As for this being a simple user error, the fact is that JSP as a technology makes such erros very easy to make and not always easy to track down. Simple html is actually very ‘loose’ unless you are writing proper XHTML and are serving it up as xml as opposed to a text mime type – missing tags get ignored by many browsers. Serving it up as XML forces the browser to make sure its valid XML – in my case Jasper isn’t even checking my JSP parts of the page are XML.

    I must admit that this may of been fixed in a later version (as I stated I have to work with an older version) however at the end of the day JSP is an awful technology to work with as time and again we get put in situations where we are using it for tasks it is completely unsuited to – we are trying to use XML as a programming/scripting language, and it is fundamentally unsuited to this task.

  7. Jon Tirsen

    I think your JSP implementation is equiped with an artificial intelligence fuzzy logic evaluator. It parsed your statement “I hate JSP” and made the decision that regardless of what the boolean expression evaluates to this has to hold true; everyone hates JSP, right?

    Is this feature in the JSP spec or is it a vendor-specific extension?

  8. Pawn

    Not everyone hates JSP. I find it quite easy and simple to work with.

    …but then again I was feed asp when I was a child.

  9. Sam Newman

    For some things JSP can be fine – I’ve used JSP since the first version was released. However it is fundamentally unsited to some tasks due to its reliance on XML as a format. Iteration is ugly but not _that_ bad. Logic branching however is really nasty and shows up just how bad XML is as a syntax for programming languages.

    I’m the first to admit that there might not be a perfect solution, however JSP has some fundamental issues which make me believe it might not be it.

  10. bluesockets

    i have to say jsp isnt easy unless you have a full depth of understanding of how the tags work, and coming from a java perspective, i dont understand half of what the tags are supposed to do so i throw them out the window and prefer to use plain old java. at least then my ide catches silly syntax errors or mal formed statements. html is a sloppy language with loose enforement on correct syntax and jsp tries to hide behind the guise of html’s ease of use, yet the important distinction is you cant turn html looseness into java strict syntax. its like trying to cast an Integer into an int. everything has its purpose, but inherently all xsp server side scripting languages fail to the point where if the developer cant pick up the slack, theres not much that can be done other than googling out an acceptable solution to the hypothetical problem.

  11. Stratos

    Struts is so bad its a geeks holiday. I have never
    seen anything so bad as STRUTS and JSP pages.

    I agree crucify struts. Its unbelievably bad.



Leave a Reply to Anthony Eden Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

%d bloggers like this: