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

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:

Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application

Leave a Comment