简体   繁体   English

无法使用 Eclipse 和 Maven 使 Struts2 Hello World 工作

[英]Unable to get Struts2 Hello World to work using Eclipse and Maven

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/ http://www.mkyong.com/misc/how-to-use-mkyong-tutorial/

I'm using:我正在使用:

  • maven: 3.2.1行家:3.2.1
  • tomcat 7雄猫 7
  • java 1.7爪哇1.7
  • Eclipse: Luna Release (4.4.0) Eclipse:Luna 发布 (4.4.0)

I'm getting this message:我收到这条消息:

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

I can never get to the login.jsp page unless I enter the full url.除非我输入完整的 url,否则我永远无法进入login.jsp页面。 But even then, when I click on the submit button, it doesn't go to the welcome_user.jsp page either.但即便如此,当我单击提交按钮时,它也不会转到welcome_user.jsp页面。

Can someone tell me how I can fix this and get this Hello World example to work in using Eclipse?有人能告诉我如何解决这个问题并使这个 Hello World 示例在使用 Eclipse 中工作吗?

If you follow the tutorial, which is linked to the page Struts 2 Hello World Example , and done everything till p.如果您按照链接到页面Struts 2 Hello World Example的教程进行操作,并完成所有操作,直到 p。 7 then you should Run it as is written 7 然后你应该像写的那样运行它

In Struts2, you can access the action class directly with a suffix of .action.在 Struts2 中,您可以直接使用 .action 后缀访问 action 类。

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

If you tried to access application as如果您尝试访问应用程序

http://localhost:8080/Struts2Example

you will get a message and 404 error code is returned to the browser.您将收到一条消息,并向浏览器返回 404 错误代码。

WARNING: Could not find action or result There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2Example].警告:找不到操作或结果没有为与上下文路径 [/Struts2Example] 关联的命名空间 [/] 和操作名称 [] 映射的操作。 - [unknown location] - [未知地点]

The workaround is to add the file to the web root folder that will redirect a browser to the correct location.解决方法是将该文件添加到 Web 根文件夹,该文件夹会将浏览器重定向到正确的位置。

index.html : 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>

Also modify web application deployment descriptor to include this file name to the welcome files list.还要修改 Web 应用程序部署描述符以将此文件名包含在欢迎文件列表中。

web.xml : web.xml :

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

That's it, if you are looking for the Hello World tutorial, you should use these references:就是这样,如果您正在寻找 Hello World 教程,您应该使用这些参考资料:

Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application 使用 Maven 创建 Struts 2 Web 应用程序来管理工件和构建应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM