I've bean doing some JSP tutorials and I don't understand what the point of a bean class is. All it is, is get and set methods. why do we use them?
public class UserData {
String username;
String email;
int age;
public void setUsername( String value )
{
username = value;
}
public void setEmail( String value )
{
email = value;
}
public void setAge( int value )
{
age = value;
}
public String getUsername() { return username; }
public String getEmail() { return email; }
public int getAge() { return age; }
}
and the jsp is
<jsp:useBean id="user" class="user.UserData" scope="session"/>
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>
Beans are a great source of fiber. That's important because most Americans don't get the recommended 25 to 38 grams each day. Fiber helps keep you regular and seems to protect against heart disease, high cholesterol, high blood pressure, and digestive illness.
Beans and legumes are excellent sources of dietary fiber, protein, B vitamins, and many other important vitamins and minerals. There is some evidence that they can help reduce blood sugar, boost heart health, and maintain a healthy gut.
That's because beans are high in fiber and a good source of protein, both of which help you feel fuller on less food. Plus, a May 2016 review in The American Journal of Clinical Nutrition found that simply adding beans to your diet (without otherwise trying to cut calories) may help you shed some body fat.
Beans and legumes Beans and legumes also keep you fuller, longer because they are so rich in fiber. Animal sources of protein, in contrast, have no fiber at all. Beans and legumes are also much higher in antioxidants.
A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm. The properties, events, and methods of a Bean that are exposed to an application builder tool can be controlled.
A Bean may be designed to operate correctly in different locales, which makes it useful in global markets.
Auxiliary software can be provided to help a person configure a Bean. This software is only needed when the design-time parameters for that component are being set. It does not need to be included in the run-time environment. The configuration settings of a Bean can be saved in persistent storage and restored at a later time.
A Bean may register to receive events from other objects and can generate events that are sent to other objects.
The use of scriptlets (those <% %>
things) is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language, those ${}
things) over a decade ago. The major disadvantages of scriptlets are:
Reusability: you can't reuse scriptlets.
Replaceability: you can't make scriptlets abstract.
OO-ability: you can't make use of inheritance/composition.
Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.
Testability: scriptlets are not unit-testable.
Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With