Java 我为什么要学习和使用struts?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3905271/
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
Why should I learn and use struts?
提问by David Parks
I'm a java developer, not seasoned, but I am familiar with most concepts reasonably well.
我是一名 Java 开发人员,没有经验,但我对大多数概念相当熟悉。
I recently built a website using Tomcat/JSP (~30 dynamic pages). I made the newbie mistake of including large sections of core logic in the JSP, using the rationalization that it's "just a simple project".
我最近使用 Tomcat/JSP(约 30 个动态页面)构建了一个网站。我犯了在 JSP 中包含大部分核心逻辑的新手错误,理由是它“只是一个简单的项目”。
I learned the hard way. So I'm re-building the app now in google app engine using servlets and planning to use Velocity to implement it using a Model-View-Controller design pattern.
我学会了艰难的方式。所以我现在正在使用 servlets 在谷歌应用引擎中重新构建应用程序,并计划使用 Velocity 使用模型-视图-控制器设计模式来实现它。
I'm also looking at Struts, but haven't used the framework before.
我也在看 Struts,但之前没有使用过框架。
Can someone convince me why I should incorporate struts into this project? Is it really going to buy me a lot for a medium sized project of one or two people?
有人能说服我为什么我应该将 struts 合并到这个项目中吗?对于一个一两个人的中型项目,它真的会给我买很多吗?
There is a clear cost in an extra learning curve with strut, will the benefits outweigh the costs? Or will the use of Velocity be enough to segregate the logic? Opinions?
使用strut的额外学习曲线有明显的成本,收益会超过成本吗?或者使用 Velocity 是否足以隔离逻辑?意见?
采纳答案by Brian
I would look longer term than this project. As you saw, first time you use any technology is largely about making mistakes and learning from them. So this first project won't likely be a shining example of Struts usage once you're done.
我会比这个项目看起来更长远。如您所见,您第一次使用任何技术在很大程度上都是为了犯错误并从中学习。因此,一旦您完成,第一个项目就不太可能成为 Struts 使用的光辉典范。
Using Struts (and Tiles from what you indicate was a main concern: JSP copy and paste) will however be an excellent delve into "proper" MVC, i.e. it forces you to do things in a particularly structured way, and one which I happened to appreciate a lot, I was a big Struts fan.
然而,使用 Struts(和你所指出的主要问题中的 Tiles:JSP 复制和粘贴)将是对“正确”MVC 的一个很好的研究,即它迫使你以一种特别结构化的方式做事,而我碰巧遇到过这种方式非常感谢,我是 Struts 的忠实粉丝。
That said, there are other options, e.g. Spring contains Spring MVC plus much much more. If you're going to invest in overcoming a learning curve, think about which framework will most benefit you overall in the medium term: which frameworks do employers in your area tend to look for, for example? At this point in time, I would go with Spring where I feel the momentum is but Struts is very good at what it does.
也就是说,还有其他选项,例如 Spring 包含 Spring MVC 以及更多。如果您打算投资以克服学习曲线,请考虑在中期总体上哪种框架对您最有利:例如,您所在地区的雇主倾向于寻找哪些框架?在这个时候,我会选择 Spring,我觉得它的势头很好,但 Struts 非常擅长它的功能。
回答by Qwerky
If you're going to learn a framework then I'd recommend Spring MVC over Struts. The learning curve isn't too steep and there are lots of Spring resources available on the internet.
如果你打算学习一个框架,那么我会推荐 Spring MVC 而不是 Struts。学习曲线不太陡峭,互联网上有很多可用的 Spring 资源。
Once you've got Spring in place you will find your application is much simpler to maintain and support. You'll also be able to add enhancements, like security, a lot easier.
一旦安装了 Spring,您会发现应用程序的维护和支持要简单得多。您还可以更轻松地添加增强功能,例如安全性。
回答by iirekm
Why you should learn Struts? My answer is: because employers often require knowledge of it, especially for maintaining of older projects. I didn't make any precise measurements, but I think that at my region JSF and Struts are used for web application development most often.
为什么要学习Struts?我的回答是:因为雇主通常需要了解它,尤其是在维护旧项目时。我没有进行任何精确的测量,但我认为在我所在的地区,JSF 和 Struts 最常用于 Web 应用程序开发。
Struts is a quite old web framework, and it's quite clumsy to write modern AJAX GUIs with it, so there were created better frameworks. JSF is for me a bit less clumsy, but also has some problems. My favourite web frameworks are Vaadin and GWT, but I'm not suggesting anything for you - you should make the decision by yourself.
Struts 是一个相当古老的 Web 框架,用它编写现代 AJAX GUI 非常笨拙,因此创建了更好的框架。JSF 对我来说不那么笨拙,但也有一些问题。我最喜欢的 Web 框架是 Vaadin 和 GWT,但我不会为您提供任何建议 - 您应该自己做出决定。
回答by Don Roby
Learning to separate the logic is excellent. You can do that without using Velocity, Struts or any framework whatsoever, and you'll likely learn more about what it takes to do this separation if you try it with minimal help first.
学习分离逻辑非常好。您可以在不使用 Velocity、Struts 或任何框架的情况下做到这一点,如果您首先在最少的帮助下进行尝试,您可能会更多地了解进行这种分离需要什么。
Learning a framework (in fact multiple frameworks) is also worthwhile, but I wouldn't personally choose Struts as a first framework unless it's the one used by your employer or a prospective employer. If your employer is using Struts, I hope it's Struts 2, as Struts 1 is getting ancient.
学习一个框架(实际上是多个框架)也是值得的,但我个人不会选择 Struts 作为第一个框架,除非它是您的雇主或潜在雇主使用的框架。如果您的雇主正在使用 Struts,我希望它是 Struts 2,因为 Struts 1 已经过时了。
The framework I like to work with the most is Wicket, but it's a radical shift from what you're currently looking at. SpringMVC is also definitely worth a look.
我最喜欢使用的框架是 Wicket,但它与您目前所看到的相比发生了根本性的转变。SpringMVC 也绝对值得一看。
If your employer is already doing web development in Java using a framework, try to learn the framework that's actually in use, and ask your co-workers for help learning it.
如果您的雇主已经在使用框架用 Java 进行 Web 开发,请尝试学习实际使用的框架,并请您的同事帮助学习它。
回答by leonbloy
First: don't let the name confuse you: Struts2 and Struts are very different frameworks.
第一:不要让名字混淆你:Struts2 和 Struts 是非常不同的框架。
Second: changing from JSP to Velocity can be a good or bad decisition, but that's not exactly the point. The point is to switch away from Model1(rather ancient nomenclature, but still useful). That is, decoupling your view layer from your logic layer. (You can use JSP or Velocity for your view layer). Furthermore, to decide your view layer is just a part of your architecture: you still must decide who will process the request and produce the data that will be sent to the view. The most basic option is to use plain servlets, but, again, it's better to use some framework. For this, there are a lot of frameworksin Java. The "action based" ones are a subset among them, perhaps the most simple to learn. Among them, the oldest is Struts; today the most used for new projects are (in no particular order) Struts2 , Spring MVC and Stripes - they are quite similar.
第二:从 JSP 更改为 Velocity 可能是一个好或坏的决定,但这并不是重点。关键是要摆脱Model1(相当古老的命名法,但仍然有用)。也就是说,将视图层与逻辑层分离。(您可以将 JSP 或 Velocity 用于您的视图层)。此外,决定您的视图层只是您架构的一部分:您仍然必须决定谁将处理请求并生成将发送到视图的数据。最基本的选择是使用普通的 servlet,但同样,最好使用一些框架。为此,有很多框架在爪哇。“基于动作”的那些是其中的一个子集,也许是最容易学习的。其中,最古老的是Struts;今天最常用于新项目的是(排名不分先后) Struts2 、 Spring MVC 和 Stripes - 它们非常相似。