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.....
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.
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
In web.xml add .extention in servlet url pattern
<servlet-mapping>
<servlet-name>PunchoutOrder</servlet-name>
<url-pattern>/PunchoutOrder.srl</url-pattern>
</servlet-mapping>
Related
I used the following Java EE Filter for some pages:
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
<url-pattern>/user/*</url-pattern>
<url-pattern>/article/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
I deployed my project on a domain, like www.mydomain.com and I set as welcome page the file index.jsp.
If I visit www.mydomain.com, it shows the welcome page, but the filter doesn't work because it doesn't match with the rule.
If I visit www.mydomain.com/index.jsp , everything is working well.
So, all I want to do is the filter matches when I visit www.mydomain.com (because index.jspis being showed).
How could I do it?
Update: I tried the following pattern, but it didn't work:
<url-pattern>/</url-pattern>
My application is running on Tomcat 7.
I've created a url rewrite filter that is listening on all incoming request, yet, when an error page is triggered, it doesn't filter it, instead it does filter the page on which the error occured.
I set up a breakpoint in the filter and when the error occurs, you can see it triggers on the source page.
But the displayed page is /desktop/index.xhtml
Is it the expected behavior ?
Here is my web.xml configuration :
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>500</error-code>
<location>/desktop/index.xhtml?messageId=4</location>
</error-page>
Is it the expected behavior ?
Yes.
Filters are by default mapped on the REQUEST dispatcher only. The below
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
is equivalent to
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
This means, the filter is only triggered on the "raw" incoming request, not on forwarded request or an error page request.
There are two other dispatchers: FORWARD and ERROR. Error pages are internally dispatched via the ERROR dispatcher. If you'd like to let your filter hook on that as well, then add it:
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Note that you need to explicitly specify the REQUEST dispatcher here, otherwise it would assume that you're overriding it altogether and are only interested in ERROR dispatcher.
Inside the filter, you can then check by the presence of a request attribute keyed with RequestDispatcher#ERROR_REQUEST_URI if it was being triggered or not.
String errorRequestURI = (String) request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);
if (errorRequestURI != null) {
// Error page was triggered on the given URI.
}
i have tried without giving servlet-name tag in my web.XML but it did not worked for me.
we are adding servlet-class & url tags in deployment descriptor file here what is the exact use of adding servlet-name tag in deployment descriptor file (web.XML).
Cant we run without servlet-name tag in our web.xml
The <servlet-name> is a unique identifier for a single Servlet. Some deployment descriptor elements some times need to refer to a specific servlet. They do that through the value of the <servlet-name>. For example, you might have multiple <servlet-mapping> elements, one for each extension. You might also have a Filter which you want applied only to a specific servlet.
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>com.pack.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<filter>
<filter-name>myFilter</filter-name>
<filter-class>com.pack.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<servlet-name>myServlet</servlet-name>
</filter-mapping>
I am working on simple web application using Servlet & Jsp. But i have
one problem where i am working on web.xml. Can i use same url pattern
for many servlet class for example
code from jsp page
<form action="Answer" method="get">
<input id="foo" type="text" name="question"/>
<input type="reset" value="Clear" />
<br/>
<input type="submit" value="Submit"/>
<input type="submit" value="Back"/>
</form>
Code from web.xml
<servlet>
<servlet-name>Answer</servlet-name>
<servlet-class>RemoveAbbr</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Answer</servlet-name>
<url-pattern>/Answer</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Answer</servlet-name>
<servlet-class>Preprocess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Answer</servlet-name>
<url-pattern>/Answer</url-pattern>
</servlet-mapping>
So, My question is what are true conditions from below options 1) if
i click on Submit button can it map to RemoveAbbr 2) if i click on
Back button can it map to Preprocess 3) creates conflict because same
url pattern(Form Action from jsp) can not used for different servlet
class name.
Every <servlet> needs to have a unique <servlet-name>, so you will need to rename one. Also, the <url-pattern>'s should be different so the servlet container will know how to handle the requests.
You need to use a unique <servlet-name>. For example:
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>com.myapp.FirstServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>SecondServlet</servlet-name>
<servlet-class>com.myapp.SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SecondServlet</servlet-name>
<url-pattern>/second.do</url-pattern>
</servlet-mapping>
Check this tutorial, there I found an example to edit web.xml file and add the servlets. Also the source code is available, so it was useful for me.
I would like to achieve the following:
/webapp-context/Page-1 -> Handled by my custom "ContentServlet"
/webapp-context/Another-Page -> Handled by my custom "ContentServlet"
/webapp-context/Page-with-long-title -> Handled by my custom "ContentServlet"
/webapp-context/_cms/<something>.zul -> Handled by ZK framework
My latest attempt looks like this (web.xml extract):
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myContentServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Unfortunately now my content servlet handles all requests (I thought the more specific pattern takes precedence?).
No conflict exists if i map my content servlet to the pattern "/webapp-context/content/*", but that's not what I want.
Thanks for your time.
I just found a solution through this question: Difference between / and /* in servlet mapping url pattern
Using '/' instead of '/*' did the trick for me.
<servlet-mapping>
<servlet-name>myContentServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>