This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Expression vs getProperty with jsp:Bean

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new and looking for some help/advice.
I have been self teaching myself Servlets and have a pretty good handle on it.

My question is around using expression with jsp:Bean vs using jsp:getProperty with jsp:Bean on my jsp pages to display session data.
Why would you use one over the other.

I am thinking that Expression just gives that extra flexibility to do more with the data right?
is that only main reason so both can be used to display data?

Sample Code:



Thank you
 
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Romsil, welcome to the Ranch!

I wouldn't use either of those things. I've been retired from work for 6 years now and I wrote a lot of JSPs before that, maybe 5 or 10 years before that. And even then jsp:useBean and jsp:getProperty were obsolete. You're much better off using the JSP Expression Language; if you're using a tutorial for your self-teaching which suggests jsp:useBean and so on then I would strongly suggest you stop using that tutorial and find a more modern one.

(It's nice that the internet never forgets anything, but the downside of that is that obsolete advice keeps being given to the unwary beginner.)
 
Paul Clapham
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me just expand on that a bit.

Modern servlet/JSP development (in which I include the projects I worked on over a decade ago) use an architecture in which the sole purpose of a JSP is to take some data and format it for output as (usually) HTML. The idea that a JSP would do some processing to produce the data to be output is banned; it's the job of a servlet (along with other Java classes) to produce that data and put it into (usually) request scope for the JSP to use. This pattern is often referred to as MVC ("Model-View-Controller").

There's a reasonably good example of the pattern here: An MVC Example with Servlets and JSP.
 
Romsil Randall
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response.
I will take your recommendation to start focusing on Expression language more in my learning.

I do understand the MVC although still new to me. I do have my jsp pages only for display purposes with no business logic.
So, I think I am moving in the right direction there.

Thanks again and really appreciate the feedback and general direction for my self education.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!