1

I am new to Struts and I have to add a functionality to a legacy system.

I have to create a servlet that's required to be accessed from a JSP page. I created one and added servlet-mapping in the web.xml file but it always shows an error like the following:

There is no Action mapped for namespace [/myServlet] and action name
   [test] associated with context path [/MyProject]

I have searched for the solution but the one I got here is for the sturts.xml entry and I am not using the struts.xml, rather I am using the annotations.

Could someone please tell me how to use excludePattern in a annotations based Struts2 project? NOTE: I tried adding the exclue-pattern in my web.xml like this:

<init-param>
  <param-name>struts.action.excludePattern</param-name>
  <param-value>/FileUploadServlet</param-value>
</init-param>

But it's still not working.

ahmar hashmi
  • 99
  • 2
  • 7
  • 1
    Just create struts.xml or use properties. Side note: Are you sure you need a servlet? – Aleksandr M Nov 16 '17 at 15:39
  • Thanks @AleksandrM for the reply. Actually I do need the servlet. I am wondering if I create struts.xml, then will my annotations work as is OR I will have to add mappings in the struts.xml instead of the annotations? – ahmar hashmi Nov 16 '17 at 16:28
  • It will work. Actually you can mix struts.xml defined actions with annotations. Also because `struts.action.excludePattern` takes patterns you can add `.*` to mapping in order to use more than one servlet. See [Jersey with Struts2](https://stackoverflow.com/q/17293115/1700321). – Aleksandr M Nov 16 '17 at 20:01

1 Answers1

1

Well, I have solved the problem by adding struts.xml to my project and adding only the constant there like this:

<constant name="struts.action.excludePattern" value="/MyServlet"/>

I was first wondering that I will have to provide all the mappings manually instead of the annotations but it worked without doing so.

ahmar hashmi
  • 99
  • 2
  • 7