无法使用 Eclipse 和 Maven 使 Struts2 Hello World 工作 [英] Unable to get Struts2 Hello World to work using Eclipse and Maven

查看:26
本文介绍了无法使用 Eclipse 和 Maven 使 Struts2 Hello World 工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该站点不允许用户向他们的教程提出技术问题,我认为这已损坏:

This site doesn't allow user to ask technical questions to their tutorial which I believe is broken:

http://www.mkyong.com/misc/how-to-use-mkyong-tutorial/

我正在使用:

  • 行家:3.2.1
  • tomcat 7
  • Java 1.7
  • Eclipse:Luna 发布 (4.4.0)

我收到这条消息:

WARNING: Could not find action or result
There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2Example]. - [unknown location]

除非我输入完整的 url,否则我永远无法进入 login.jsp 页面.但即便如此,当我单击提交按钮时,它也不会转到 welcome_user.jsp 页面.

I can never get to the login.jsp page unless I enter the full url. But even then, when I click on the submit button, it doesn't go to the welcome_user.jsp page either.

有人能告诉我如何解决这个问题并使这个 Hello World 示例在使用 Eclipse 中工作吗?

Can someone tell me how I can fix this and get this Hello World example to work in using Eclipse?

推荐答案

如果您按照教程进行操作,链接到页面 Struts 2 Hello World 示例,直到 p.7 那么你应该运行它就像写的那样

If you follow the tutorial, which is linked to the page Struts 2 Hello World Example, and done everything till p. 7 then you should Run it as is written

在Struts2中,可以直接使用后缀访问action类.动作.

In Struts2, you can access the action class directly with a suffix of .action.

http://localhost:8080/Struts2Example/User/Login.action

如果您尝试访问应用程序

If you tried to access application as

http://localhost:8080/Struts2Example

您将收到一条消息,并向浏览器返回 404 错误代码.

you will get a message and 404 error code is returned to the browser.

警告:找不到操作或结果没有映射的操作与上下文路径关联的命名空间 [/] 和操作名称 [][/Struts2 示例].- [未知地点]

WARNING: Could not find action or result There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2Example]. - [unknown location]

解决方法是将文件添加到 Web 根文件夹,以便将浏览器重定向到正确的位置.

The workaround is to add the file to the web root folder that will redirect a browser to the correct location.

index.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=User/Login.action">
</head>

<body>
<p>Loading ...</p>
</body>
</html>

还要修改 Web 应用程序部署描述符以将此文件名包含在欢迎文件列表中.

Also modify web application deployment descriptor to include this file name to the welcome files list.

web.xml:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

就是这样,如果您正在寻找 Hello World 教程,您应该使用这些参考资料:

That's it, if you are looking for the Hello World tutorial, you should use these references:

使用 Maven 创建 Struts 2 Web 应用程序管理工件和构建应用程序

这篇关于无法使用 Eclipse 和 Maven 使 Struts2 Hello World 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆