Unable to get Struts2 Hello World to work using Eclipse and Maven

两盒软妹~` 提交于 2019-11-27 05:32:59

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

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

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

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

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>

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>

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!