java Struts有什么好处

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1276177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:54:26  来源:igfitidea点击:

What Are the Benefits of Struts

javamodel-view-controllertomcatservletsstruts

提问by ZZ Coder

I recently added Struts 1.3 to my application on Tomcat. Here are my observations,

我最近在 Tomcat 上的应用程序中添加了 Struts 1.3。以下是我的观察,

  1. MVC. Servlet/JSP does this fine for me, where JSP is the view and servlet is the controller. I don't see any benefit to get the mapping from an XML file since our mapping is very static.
  2. Action Form. I can see some benefits of action form but not huge.
  3. Tags. I already uses JSTL and don't see any advantage using Struts tags.
  1. MVC。Servlet/JSP 对我来说很好,其中 JSP 是视图,servlet 是控制器。我认为从 XML 文件获取映射没有任何好处,因为我们的映射非常静态。
  2. 行动表。我可以看到动作形式的一些好处,但不是很大。
  3. 标签。我已经在使用 JSTL 并且没有看到使用 Struts 标签的任何优势。

So I am thinking about removing Struts. Anyone can think of any other benefits I might have missed?

所以我正在考虑删除 Struts。任何人都可以想到我可能错过的任何其他好处?

回答by Saeros

Personally I myself prefer jsp/servlet but theoretically Struts has some advantages. Here are some of the advantages i know of, you might have mentioned them already, but i thought it would be better if i list all of them here.

我个人更喜欢 jsp/servlet,但理论上 Struts 有一些优势。以下是我所知道的一些优点,您可能已经提到过它们,但我认为如果我在这里列出所有优点会更好。

  1. Centralized File-Based Configuration. Struts values/mapping are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout.

  2. Form Beans.

  3. Bean Tags. Struts provides a set of custom JSP tags that let you easily output the properties of JavaBeans components.

  4. HTML Tags. Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes:

    • It lets you get initial form-field values from Java objects.
    • It lets you redisplay forms with some or all previously entered values intact.
  5. Form Field Validation. Struts has a robust, extensible validator that can be used to uniformly validate your form fields. This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript).

  6. "Plumbing code" contained within the Struts framework. Mapping HTTP request parameters to Java objects is handled by Struts, for example. You don't have to do it. This allows you to focus more on the domain problem instead of building infrastructure.

  7. Good documentation & plenty of books. If you have to leave the project and/or someone else has to maintain it then using a well known and well documented framework will make that job much easier. A homebrewed framework just can't match that.

  8. Broad user testing. Since Struts is used in plenty web-apps the framework will get looked at by many more eyes than anything you could write alone. Usually, but not always, that means any problems you have will have been seen by someone else (and hopefully resolved) first.

  1. 集中的基于文件的配置。Struts 值/映射在 XML 或属性文件中表示。这种松散耦合意味着无需修改或重新编译 Java 代码即可进行许多更改,并且可以通过编辑单个文件进行大量更改。这种方法还可以让 Java 和 Web 开发人员专注于他们的特定任务(实现业务逻辑、向客户端呈现某些值等),而无需了解整个系统布局。

  2. 形式豆。

  3. 豆标签。Struts 提供了一组自定义 JSP 标记,让您可以轻松地输出 JavaBeans 组件的属性。

  4. HTML 标签。Struts 提供了一组自定义 JSP 标记来创建与 JavaBeans 组件相关联的 HTML 表单。这个 bean/form 关联有两个有用的目的:

    • 它允许您从 Java 对象获取初始表单字段值。
    • 它可以让您重新显示一些或所有以前输入的值完好无损的表单。
  5. 表单字段验证。Struts 有一个健壮的、可扩展的验证器,可用于统一验证您的表单字段。这种验证可以在服务器上执行(用 Java),也可以在服务器和客户端上执行(用 JavaScript)。

  6. “管道代码”包含在 Struts 框架中。例如,将 HTTP 请求参数映射到 Java 对象是由 Struts 处理的。你不必这样做。这使您可以更多地关注领域问题,而不是构建基础架构。

  7. 良好的文档和大量的书籍。如果您必须离开项目和/或其他人必须维护它,那么使用众所周知且记录良好的框架将使这项工作变得更加容易。自制框架无法与之匹敌。

  8. 广泛的用户测试。由于 Struts 用于大量网络应用程序,因此该框架将比您单独编写的任何内容都被更多的人看到。通常,但并非总是如此,这意味着您遇到的任何问题都会首先被其他人发现(并希望得到解决)。

回答by henrik

Large knowledge base. I agree that this perhaps isn't as valid as it used to be but Struts has been used in a lot of projects over the years. From a maintainability point of view using a well known framework makes it easier for other people to work on your application and also help build your own resumé for the future. Right now most development is either in the component based space (like JSF, wicket, tapestry) or in the rails-like space (like rails, grails, lift) but the struts arcitechture is still in use and valid.

庞大的知识库。我同意这可能不像以前那样有效,但多年来 Struts 已在许多项目中使用。从可维护性的角度来看,使用众所周知的框架可以让其他人更轻松地处理您的应用程序,也有助于为未来构建自己的简历。现在大多数开发要么在基于组件的空间中(如JSFwickettapestry)要么在类似rails 的空间中(如railsgrailslift),但 struts 架构仍在使用和有效。

You didn't say if you develop in a corporate environment or not, for a personal project perhaps the maintainability issue isn't that much of a problem.

你没有说你是否在公司环境中开发,对于个人项目来说,可维护性问题可能不是什么大问题。

If you decide that struts suits you well you could also have a look at stripes, a struts-like framework that's based on the same concepts but is less verbose when it comes to configuration with more sensible defaults, less xml and support for annotations.

如果您认为 struts 很适合您,您还可以看看stripes,这是一个类似 struts 的框架,它基于相同的概念,但在配置方面不那么冗长,具有更合理的默认值、更少的 xml 和对注释的支持。

回答by Nick Holt

I totally agree with your points about Struts - personally I think its time has come and gone.

我完全同意你关于 Struts 的观点——我个人认为它的时代已经过去了。

I went off Struts in v1 (which I believe is nothing like the latest versions) because the form beans where just added boilerplate code to write.

我在 v1 中放弃了 Struts(我认为它与最新版本完全不同),因为表单 bean 刚刚添加了要编写的样板代码。

Since then most applications I've worked on are using Spring as the dependency injection framework, which has made Spring MVC the natural choice - it's simple, straight forward and minimal.

从那时起,我处理的大多数应用程序都使用 Spring 作为依赖注入框架,这使得 Spring MVC 成为自然的选择——它简单、直接且最小。

回答by sourcerebels

Not just for Struts. But some points to consider for using a framework:

不仅适用于 Struts。但是使用框架需要考虑的一些要点:

  • Standarization.
  • Specialized IDE or plugins for your favourite IDE.
  • Portability. For example, someone can develope a portlet for integrate your existing struts application in a portal server.
  • Internationalization.
  • 标准化。
  • 您最喜欢的 IDE 的专用 IDE 或插件。
  • 可移植性。例如,有人可以开发一个 portlet 来将您现有的 struts 应用程序集成到门户服务器中。
  • 国际化。

The most important for me:

对我来说最重要的:

  • You dont have to worry about the issues on the struts code, just upgrade.
  • You can focus your work in business logic.
  • 不用担心struts代码的问题,升级就行。
  • 您可以将工作重点放在业务逻辑上。

回答by Biju CD

Struts is Open Source-- Large Community---- Number of Books available----- Proven FrameWork---- Popular framework----- Available since 2001---- +---- the features mentioned above...........

Struts 是开源的——大型社区——可用的书籍数量————经过验证的框架——流行的框架————自 2001 年以来可用——+---- 上面提到的特性…………

but when u r using struts,the better choice is struts2.

但是当你使用struts时,更好的选择是struts2。

回答by John O

I think your feeling about removing Struts is a sound and understandable reaction. Struts just doesn't seem to do very much for an application.

我认为您对删除 Struts 的感觉是一种合理且可以理解的反应。Struts 似乎对应用程序没有多大作用。