如何使 ActionBean 立即实例化,而不是在我调用处理程序之一之后实例化?
我正在尝试用 Stripes 做一些简单的事情。我读过并听说过很多关于使用这个框架的易用性以及陡峭的学习曲线(即学习非常快且富有成效)的内容。
但到目前为止,我什至无法用 Stripes 创建最简单的 HelloWorld。
我发现的所有示例都演示了如下功能:“单击链接 --> 查看结果”。当我们点击链接时,特殊的处理程序被调用(它返回Resolution
),之后 getter 也可以工作(因为 bean 被实例化)。
但是,如果我不需要链接,但想要简单的静态信息(例如,当我打开 StackOverflow 时,我不需要单击链接,但我会立即看到问题列表),那么这对于 Stripes 来说就很重要了在我看来,因为 bean 没有立即实例化。
如何解决这个问题?是否有一些特殊的注释或其他技术?
这里有人尝试过Stripes并遇到同样的问题吗?我真的很沮丧,也许我错过了一些东西..
UPD:可能不清楚,因为我没有附加任何代码。所以我描述得更多一些。为了重现我的情况,从 QuickStart 获取代码就足够了并尝试从 ActionBean getters 检索文本(当前,文本在 jsp 中硬编码)。该文本仅在您按下按钮后才会出现(即在处理程序完成一些工作后)。但第一次打开页面后,您将看不到文字。
I'm trying to make something simple with Stripes. I've read and heard a lot about easiness of using this framework and about steep learning curve (i.e. learning is quite fast and productive).
But till this moment I can't even create the simplest HelloWorld with Stripes.
All examples I've found demonstrate functionality like: "click on the link --> see the result". When we click on the link special handler is called (which returns Resolution
) and after that getters also works (because bean is instantiated).
But if I don't want a link but I want simple static information (for example, when I open StackOverflow I don't need to click a link, but I immediately see a list of questions) then it's something non-trivial for Stripes as it seems to me, because bean is not instantiated immediately.
How to fix that? Are there some special annotation or another technique?
Have anyone here tried Stripes and met the same problem? I'm realy frustrated, maybe I've missed something..
UPD: it's probably not clear because I haven't appended any code. So I describe a bit more. In order to reproduce my situation it's enough to get the code from QuickStart and try to retrieve text from ActionBean getters (currently, text is hard-coded in jsp). The text will appear only after you press the button (i.e. after handler does some work). But after you open the page first time you won't see the text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您熟悉 MVC 模式吗(请参阅 http:// en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)? MVC 的关键部分之一是您永远不会直接调用 JSP。您不会访问 www.myservername.com/myjsp.jsp。相反,您可以访问 www.myservername.com/mything.action。 Stripes 将进行一些处理,设置一些内容,然后将您发送到特定的 JSP。
从你的问题来看,听起来你正试图直接进入 JSP。停止这样做,你会和条纹相处得更好。
至于当您访问 www.myservername.com 时会发生什么,您会转到 web.xml 中的welcome-文件。你做了这样的事情
(是的,你直接违反了关于没有jsp的规则)
然后在index.jsp中你将其设置为一个单行文件,如下所示:
当有人第一次访问你的网站时,他们点击index.jsp,这会发送他们到一个动作,填充内容并转发它们。在其他情况下,用户不会直接访问 jsp,索引文件只不过是实际操作的转发。
Are you familiar with the MVC pattern( see http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller )? One of the key parts of the MVC is you never ever call the JSP directly. You don't go to www.myservername.com/myjsp.jsp. Instead, you go to www.myservername.com/mything.action. Stripes will do some processing, set some stuff, and then send you on to the specific JSP.
From your question, it just sounds like you are trying to go directly to JSPs. Stop doing that, and you will get along much nicer with stripes.
As for what happens when you just go to www.myservername.com, you go to the welcome-file in your web.xml. You do something like this
(yes you break the rule about no jsp directly)
Then in index.jsp you make it a 1 line file like so:
And the first time someone goes to your site, they hit index.jsp, which sends them to an action, which populates stuff and forwards them on. In no other cases will the user directly get to a jsp, and the index file is nothing but a forward to a real action.