无法使用 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/

我正在使用:

  • maven: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 Example,并完成了所有工作,直到 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类,后缀为.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.

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

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:

  • Hello World
  • Hello World 使用 Struts 2李>
  • 如何创建一个 Struts2 网页应用

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

相关文章