• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Coding Conventions/Best Practices

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

As part of a project that I am working on I need to either find or develop coding conventions and best practices for developing JSP. So far a Google search for such has been largely unsuccessful. Are there any industry recognized coding conventions and best practices for JSP and if so, where can I find them?
[ April 10, 2006: Message edited by: Linda Walters ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Modern best-practices are leaning towards scriptless JSP pages that employ the JSTL and EL, along with custom actions (tags), to replace what used to be done with scriptlets. Without any Java code on the pages, coding conventions become a simple matter of dictating how the EL should be used to reference scoped variables.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've also read that only request attributes should be used by JSP.
There's a whole chapter about JSP/JSTL usage in J2EE Design and Architecture.
You might be interested in it.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
I've also read that only request attributes should be used by JSP.



Huh? I don't know where you read that but it makes no sense. Page context is an exteremly valuable location for scoped variables, especially when using the JSTL, and each of session and application scopes are essential to well-structured applications.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I was referring to "Expert One-On-One J2Ee Design and Development".
I remember that jsp views should only use the needed data from the request scope. It is not the role of views to deal with scope attributes.
I read this a long time ago I'll give it another shot tonight.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found it, I didn't dream

It says, p537 :
"Views shouldn't be given access to session data, as they might modify it, subverting good design."

Another one in the JavaBeans section:
"There are four values for scope : page, request, session and application, of which only one (request) is compatible with correct use of JSP in an MVC web application, as views shouldn't access (and potentially manipulate) session or application-wide state."
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Professional JSP 2nd Editionhas chapter named Maintainability and Good Practice - read it. I can't recall the content.
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is one of the good article to start with:
Best Practices to improve Performance in JSP
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even the following site provide some good practices:

http://www.javapractices.com/TableOfContents.cjp
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Found it, I didn't dream

It says, p537 :
"Views shouldn't be given access to session data, as they might modify it, subverting good design."

Another one in the JavaBeans section:
"There are four values for scope : page, request, session and application, of which only one (request) is compatible with correct use of JSP in an MVC web application, as views shouldn't access (and potentially manipulate) session or application-wide state."



I think that that is all complete nonsense. Just because you read something in a book doesn't always make it gospel.

While I can agree that views should generally be idempotent, pretending the other scopes do not exist "because they might accidentally modify them" is patently ridiculous. One might as well say "don't write any code because you might introduce a bug".
[ April 11, 2006: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume if you did a google search you did find JSP1.x code conventions?
It would be a good place to start, even if it is a little out of date.

Other things I might mention:
${user.name} vs <c:out value="${user.name}"/>
Even though a JSP2.0 container will recognise an EL expression on its own, still use the <c:out> tag as it escapes undesirable HTML characters.

Specifying access scope of variables in EL
${user} is equivalent to pageContext.findAttribute("user") which searches through the scopes page, request, session, application in that order, using the first it finds.
${sessionScope.user} specifies the "user" attribute in session scope specifically.
It can be argued you should always specify the scope of the attribute, both for documenting where you expect it to be, and preventing potential errors from the same attribute name being used in multiple scopes.

Cheers,
evnafets
[ April 11, 2006: Message edited by: Stefan Evans ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Just because you read something in a book doesn't always make it gospel.


I agree. I thought I'd read that somewhere, that's all.
Somebody is asking about good practices in JSP, and I 'kindly' gives him some information. It could help to have different sources.
I'd argue about saying that it is "complete nonsense", but you're the boss

PS : are you angry or something ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
I'd argue about saying that it is "complete nonsense", but you're the boss



Actually, no I'm not. When chiding someone for naming convention violations, or being not nice, then I'm the boss.

When answering questions, I'm just a contributor like anyone else. So if you disagree with me, feel free to say so. I would however, ask that if we are going to discuss the merits of scoped variable usage in JSPs, that another thread be started. We've already hi-jacked Linda's poor thread pretty badly.

are you angry or something ?



Of course not. Though some people have said that I tend to "sound" angry when writing... but be assured that it is not so.

Perhaps it's because I am outspoken when I hear what I think is rubbish. But angry? No.
[ April 11, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Though some people have said that I tend to "sound" angry when writing...


funny, I've been told the same
Thanks for the reply.
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic