Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struts.action.excludePattern not working,

struts.action.excludePattern is not working for me in Struts 2, i had place servlet cal in form action, form will submit on hyperLink click.

struts.xml:

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

web.xml

  <servlet>
    <description></description>
    <display-name>PunchoutOrder</display-name>
    <servlet-name>PunchoutOrder</servlet-name>
    <servlet-class>com.PunchoutOrder</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>PunchoutOrder</servlet-name>
    <url-pattern>/PunchoutOrder</url-pattern>
  </servlet-mapping>

jsp:

<form id="form1" name = "form1" method="post" action="PunchoutOrder">
<input type="image" alt="Submit" src="images/submit.png" onclick="Submit(form1);return false;"/>

Getting below Error:

15:26:37,512 WARN  [Dispatcher] Could not find action or result
There is no Action mapped for namespace / and action name PunchoutOrder. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)

Am i missing something...........?

Thank you.....

like image 604
Warrior Avatar asked Dec 21 '22 16:12

Warrior


2 Answers

I was having the same problem and ran into several hints at how to fix it. However the solution I found, at least in Struts 2.2.2 was that I was using the wrong filter in my web.xml. After some digging through Google and SO posts I found that changing from:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

To:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

After changing the filter, my exclusion pattern constant in the struts.xml immediately started functioning as expected.

This is also documented here: https://cwiki.apache.org/confluence/display/S2WIKI/Troubleshooting+guide+migrating+from+Struts+2.0.x+to+2.1.x#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-FilterMapping%2CdefaultActionextensions%2CandServlets

Although the previous entry says to explicitly declare the action extensions, I found it was unnecessary after fixing my filter declaration.

like image 136
Russell Shingleton Avatar answered Feb 19 '23 19:02

Russell Shingleton


it seems as if your syntax isn't entirely correct. I fell upon the same issue and correcting the regular expression worked for me. After adding the line

<constant name="struts.action.excludePattern" value="/exclude/.*?"/>

to my struts.xml, everything works as expected. Request within this path are now returned with 404 errors instead of struts error message "There is no Action mapped for namespace ..."

cheers

like image 30
mana Avatar answered Feb 19 '23 18:02

mana