Hello Friends, i have a query, why to use beans in my jsp page as beans are also java classes and i can use it otherwise also. Like instantiating in in scriplets. are there any specific advantages of using <jsp:useBean> tag. thanks
Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Joined: Nov 22, 2001
JavaBeans follow a specific naming convention which allows jsp tags to access and retrieve values easily. You can achieve the same by scriptlets, however using scritplets extensively in JSP page is not recommended as that can lead to unmaintainable "Spaghetti Code".So the question is not "Why JavaBeans?" but why not scriptlets.
Joined: Jan 30, 2000
Your question doesn't mention using servlets also. Sure JavaBeans are also classes. But you said: "Like instantiating in in scriplets..." WAIT! Unless your app is simple, by now the recommended pattern for Java Web apps is the MVC (AKA "Model 2"). Look it up in the literature. It uses a Java Servlet(s) as a "traffic cop" (controller) directing the "action" (request) to where it needs to be serviced and usually creates a bean or two which it then places in request scope (unless session scope is *REALLY* needed). The JSP uses the :usebean tag and you get the picture, right? Also by now, the framework STRUTS has pretty much simplified the problem of implementing Java Web apps. "Read All ABout It": http://www.amazon.com/exec/obidos/ASIN/0596003285/electricporkchop and http://www.amazon.com/exec/obidos/ASIN/1930110502/electricporkchop
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
Joined: Sep 14, 2002
Struts is nice and all but I feel like there is major overhead using it. If the application is large and JSPs/Servlets begin to get too "messy", then I'll consider Struts. But for most smaller apps, simple JSPs/Servlets is fine.