• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP 2.0 JSTL

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Just wandering if anyone could help me out with a quick fix.

I'm looking for a quick simple example of JSP2.0 with JSTL or EL to connect to a Bean.

I have seen examples of how you retrieve data from a Bean but I was wondering if someone could throw in a quick example of populating a Bean, say for a registration page
of a site or something.

Something simple like this:-


JSP
 
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
I assume that you mean after submitting a form? If so, then this is something that should be done in a servlet rather than a JSP. You could use <c:set> for this in a JSP, but submitting form data directly to a JSP would be considered a poor practice.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the (legacy) jsp:useBean for that. But I agree with Bear that it should be done at in a servlet. That's the right approach nowadays. There are utilities and frameworks available which can populate beans for you 'automagically', for example Apache Commons Beanutils. If you want to do it at a bit higher level, consider JSF or Struts. In both MVC frameworks you've only 'action beans' and there is no need to write a servlet yourself.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I assume that you mean after submitting a form? If so, then this is something that should be done in a servlet rather than a JSP. You could use <c:set> for this in a JSP, but submitting form data directly to a JSP would be considered a poor practice.


So basically the only was is to use the old



There's no way of accessing a Bean directly from the JSP and setting the property?

OK, just wondered if JSP/Servlet had a way of accessing Beans directly (JSF style)

Cheers
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP/Servlet is just a basic API. JSF API extends JSP/Servlet with seamless bean-mapping like that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic