Skip to content
Advertisement

No action mapped error while running Struts 2 app on Netbeans 7.3.1

Trying to build a Struts 2 app which directs the user to a page (Display.jsp) that shows the color of a user defined RGB color configuration. I get the example from the Struts 2 Tutorial by Budi Karniawan. When I manually cut and paste the source code and build the app manually as an NB Web application, it runs fine although the RGB parameters throw validation errors despite being input in the correct format (I checked that I am inputting using comma separated numbers for the RGB co-ordinates ie: green is 0,255,0). The directory structure is:

enter image description here

Then I decided to import the project file (creating a Web Application from Existing Sources option). I used the ant build.xml file to compile and run the application.

When I run the application through the app name:

JavaScript

I get:

JavaScript

Then I append the action name mapped in struts.xml

JavaScript

I get an HTTP 404. But the above Deisgn1.action reference worked when I tried to build the project manually. Can anyone please tell me the best way to correctly import and run this application given the following files? I would rather use an ant script and NOT MAVEN (since there seems to be a lot of issues building Struts 2 using Maven). I would just like to know a way to avoid the 404 error when trying to run struts actions.

If I try building the app manually, the input validation fails (even though I’m inputting the numbers and separating them with commas). If I try to import and use Ant to ensure a correct build, I end up with a 404.

The app is as follows:

web.xml:

JavaScript

struts.xml:

JavaScript

Color.java:

JavaScript

Design.java:

JavaScript

MyColorConverter.java:

JavaScript

Design.jsp:

JavaScript

Display.jsp:

JavaScript

I tried to change the web contents folder from /jsp to / so that project structure is the same as the directory structure. I then use the ant build script to compile and run the project and get the following stack:

JavaScript

Advertisement

Answer

Well here’s how I solved it. I used the Netbeans ‘Web Applications with Existing Sources’ to import the project. For some reason the imported project doesn’t register the ‘jsp’ directory. It just sees the JSP files in the Web Pages directory NOT Web Pages/jsp. So i simply removed the /jsp reference in the struts.xml. The app now runs fine and the validation errors are no longer there.

I’m happy with this answer to the extent that I can run the app, but I’m not happy that I fully understand how IDEs build these type of applications as the imported directory structure is clearly wrong (and missed the jsp folder). Would be grateful if anyone could shed further light on this or if I should post a separate question on the topic of building Struts2 in Netbeans

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement