eclipse 上的 struts 设置示例应用程序
我是 strut/web 编程的新手,我认为通过阅读示例应用程序可以学到很多东西。 在谷歌上,我搜索并找到了一个示例应用程序 http://www.roseindia.net/struts/struts2/struts2tutorial.zip ,该教程非常好,它提供了一个示例登录页面。
但是,我无法运行这个示例应用程序。 我尝试在roseindia.net 网站上发帖,但也没有得到任何帮助。
服务器启动期间没有记录任何错误,但是当我尝试打开 helloworld 的链接之一时,会输出以下
错误
严重:找不到操作或结果没有映射的操作 动作名称 HelloWorld. - [未知位置]
我的 Eclipse 上这个东西的文件夹结构是
/WebContent/WEB-INF/java/net/roseindia/Struts2HelloWorld.java
/WebContent/pages/HelloWorld.jsp
/WebContent/WEB-INF/struts.xml
在 strut.xml 中,示例有..
<action name="HelloWorld" class="net.roseindia.Struts2HelloWorld">
<result>/pages/HelloWorld.jsp</result>
</action>
我怀疑 strut.xml 中的某些内容是错误的? 我正在使用 eclipse J2EE 和 tomcat6,我已经尝试在roseindia 的网站上发帖,但没有得到任何帮助。
I am new to strut/web programming and I thought I could learn a lot by reading a sample app. On google, I searched and found a sample app at
http://www.roseindia.net/struts/struts2/struts2tutorial.zip , the tutorial is really nice and it gives a sample login page.
However, I couldn't run this sample app. I tried posting on the roseindia.net site and got no help neither.
There is no error logged during the start of the server, but when I try and open one of the helloworld's link the following is outputted
I am getting this error
SEVERE: Could not find action or result There is no Action mapped for
action name HelloWorld. - [unknown location]
The folder structure of this thing on my eclipse is
/WebContent/WEB-INF/java/net/roseindia/Struts2HelloWorld.java
/WebContent/pages/HelloWorld.jsp
/WebContent/WEB-INF/struts.xml
while in strut.xml the sample had..
<action name="HelloWorld" class="net.roseindia.Struts2HelloWorld">
<result>/pages/HelloWorld.jsp</result>
</action>
I am suspecting something in the strut.xml is wrong? I am using eclipse J2EE and tomcat6, I have already tried posting on roseindia's site and got no help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过阅读示例应用程序,您将学到很多东西。 如果您的样本不起作用,则可能您的样本是错误的。
也许您需要实际的权威文档。 请参阅如何使用 Eclipse 设置基本的 struts 项目。 这是与任何 Eclipse - Struts 文档一样的官方文档。
也许您需要一个更好的例子。 有关大量示例,请参阅 Struts 社区项目和示例网站。
You will learn a lot by reading sample apps. If your sample doesn't work, perhaps your sample is wrong.
Perhaps you need the actual authoritative documentation. See How to setup a basic struts project using Eclipse. This is the as official as any Eclipse - Struts documentation can be.
Perhaps you need a better example. See the Struts Community Projects and Examples web site for numerous examples.
您将文件命名为“strut.xml”还是“struts.xml”? 它应该是后者(尽管如果您愿意,您可以覆盖它)。 另外,在 Struts 2 中,struts.xml 文件必须位于类路径中,而不是位于 WEB-INF 的根目录中。 因此,在您的项目中,您应该放入“src”文件夹,这样当它部署时,它就会进入 WEB-INF/classes。 您可以通过将 Web 应用程序“导出”到 WAR 文件并验证它进入 WEB-INF/classes 来验证它是否进入正确的位置。
Did you name the file "strut.xml" or "struts.xml"? It should be the latter (although you could override it if you wanted). Also, in Struts 2 the struts.xml file has to be in the classpath, not at the root of WEB-INF. So, in your project, you should put in the "src" folder, so when it deploys it goes into WEB-INF/classes. You can verify it goes into the correct place by doing an "Export" of the web application to a WAR file and verifying it went into WEB-INF/classes.
我刚刚下载了本教程的副本,并将其部署到 Tomcat 6 - 并且它有效!
也许自您上次尝试以来他们已经修复了该错误? 或者您的 Eclipse 配置方式可能有问题。
我所做的就是解压教程; 将目录复制到Tomcat的webapps目录中; 启动Tomcat; 导航至我的 PC 上的 Tomcat 管理器页面; 并单击 struts2tutorial 应用程序的链接。
再试一次...
I've just downloaded a copy of this tutorial, and deployed it to Tomcat 6 - and it works!
Perhaps they have fixed the bug since you last tried? Or perhaps there's something wrong with the way you have Eclipse configured.
Al I did was to unzip the tutorial; copy the directory into the Tomcat webapps directory; start Tomcat; navigate to the Tomcat manager page on my PC; and click the link to the struts2tutorial application.
Give it another try...
我在 Eclipse 中遇到了同样的问题,并通过将源文件夹的输出文件夹更改为:
I had the same issue in Eclipse and solved it by changing the output folder of the source folder to: