豆子有什么意义?

编程入门 行业动态 更新时间:2024-10-17 22:18:03
本文介绍了豆子有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在做一些JSP教程,我不明白bean类的意义。它只是获取和设置方法。我们为什么要使用它们?

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; }

}

和jsp是

<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>

推荐答案

  • A Bean获得了Java一次编写,随处运行范例的所有好处。 可以控制暴露给应用程序构建器工具的Bean的属性,事件和方法。

  • 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.

    Bean可能被设计为在不同的语言环境中正常运行,这使得它在全球市场中有用。

    A Bean may be designed to operate correctly in different locales, which makes it useful in global markets.

    可以提供辅助软件来帮助人配置Bean。只有在设置该组件的设计时参数时,才需要此软件。 不需要包含在运行时环境中。 Bean的配置设置可以保存在持久存储中,并在以后恢复。

    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.

    Bean可以注册以接收来自其他对象的事件,并可以生成将发送给其他对象的事件。

    A Bean may register to receive events from other objects and can generate events that are sent to other objects.

    • Bean的优点

    使用 scriptlet (那些< %%> 的东西)确实非常气馁,因为taglibs诞生了(比如 JSTL )和EL(表达式语言,那些 $ {} 的东西)十多年前。 scriptlet 的主要缺点是:

    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:

  • 可重用性:您无法重用scriptlet。

  • Reusability: you can't reuse scriptlets.

    可替换性:您不能将scriptlet抽象化。

    Replaceability: you can't make scriptlets abstract.

    OO-ability:你不能使用继承/组合。

    OO-ability: you can't make use of inheritance/composition.

    可调试性:如果scriptlet中途抛出异常,你得到的只是一个空白页面。

    Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.

    可测试性:scriptlet不是单元可测试的。

    Testability: scriptlets are not unit-testable.

    可维护性:每个saldo需要更多时间来维护混杂/混乱/重复的代码逻辑。

    Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.

    • 检查整个... BalusC的回答
  • 更多推荐

    豆子有什么意义?

    本文发布于:2023-11-02 16:52:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1552912.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:豆子   有什么意义

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!