What is the difference struts2 URL pattern below types?
<url-pattern>*.do</url-pattern>
<url-pattern>/struts/*</url-pattern> and <url-pattern>/*</url-pattern> ?
<url-pattern>/*</url-pattern> // for all requests
<url-pattern>*.do</url-pattern> // for all requests which contains extinction .do
<url-pattern>/struts/*</url-pattern> // for all contains path like struts/
Related
I am using struts 2. In my web.xml I am having the following configuration,
<filter>
<description>filter for application</description>
<display-name>AppBasicFilter</display-name>
<filter-name>AppBasicFilter</filter-name>
<filter-class>com.myapp.AppBasicFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>AppBasicFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
For this configuration, I am getting my action classes triggerd properly. But Neither before nor after action class execution, my AppBasicFilter is not getting triggerd.
I tried to decompile and see the struts 2 FilterDispatcher coding, I saw that if mapping is present, its not doing FilterChain.doFilter() in it.
This problem is because of that. can someone please help me?
I came to know that its a problem with FilterDispatcher. So I have to work with StritsPrepareAndExecuteFilter which is available in struts 2.1 or greater. But unfortunately my project was using struts 2.0. So I migrated to struts 2.1 and made it work.
I am working in the struts2 web application.I want to do the mapping of my url such that the extensions like ".jsp" should be eliminated from the url.
So below is the snippet code of my web.xml.I want to do that my url show /login instead of /login.jsp.
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>URLFilter</filter-name>
<filter-class>example.MyFilter</filter-class>
<init-param>
<param-name>onError</param-name>
<param-value>/login.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>URLFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Just access all your JSPs through Actions (and put them somewhere below WEB-INF to enforce this policy). It's easy to do with the "default action" of Struts2:
<action name="login">
<result>/WEB-INF/pages/login.jsp</result>
</action>
I don't know how well this integrates with ServletFilter, maybe you'll have to turn the one mentioned in your web.xml into a Struts2 Interceptor.
You can change url extension using property file as shown in below link :
http://www.aoiblog.com/change-url-extension-in-struts2/
Im trying to create a special web.xml for local development.
I have some tags stored in a separate xml-file which need to be selected and pasted to specific positions inside the final web.xml.
To achieve this I am using the copy and the paste action in the following manner:
<xmltask source="templates.xml">
<copy path="//data/init-param" buffer="initParamBuffer"/>
</xmltask>
<xmltask source="web.xml" dest="web.xml">
<paste path="//web-app/filter[contains(./filter-name,'MyFilter')]
/init-param[contains(./param-name,
'MyInitParameter')]"
position="after" buffer="initParamBuffer"/>
</xmltask>
My intention is to gather ALL init-param Tags from the source File and paste them after the Tag selected in the paste operation.
Also the Part where Im selecting a Tag which contains a tag with a specified content using the contains() function is not working smoothly either.
Maybe there is a better way to form this xpath expression...
update:
As I have written before, I do not know the best approach to this problem. I have read about the possibility to transform using stylesheets, but since the ant-xmltask promised to be a more sleak sollution I have tried this first.
As far as I have come with this approach, it is possible to insert/write tags into the web.xml using this approach. I have succeeded in inserting single init-param tags at locations that where sligtly off, with a less complex expression:
<paste path="//web-app/filter[1]/init-param"
position="after" buffer="initParamBuffer"/>
So my Problem was:
A: I want to select more than one tag into the buffer
B: I want to insert the content of that buffer after a tag specified by a name (not index).
Here is an example for the sources (templates.xml) to insert into the web.xml:
<data>
<init-param>
<param-name>newparam1</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>newparam2</param-name>
<param-value>2</param-value>
</init-param>
</data>
Here is part of an web.xml where the above section is to be pasted:
<web-app>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<url-pattern>/somePath/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/myPath/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>foo.bar.SomeFilter</filter-class>
<init-param>
<param-name>SomeInitParameter</param-name>
<param-value>4711</param-value>
</init-param>
</filter>
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>foo.bar.MyFilter</filter-class>
<init-param>
<param-name>MyInitParameter</param-name>
<param-value>0815</param-value>
</init-param>
</filter>
</web-app>
And here is the result I would hope to achieve:
<web-app>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<url-pattern>/somePath/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/myPath/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>foo.bar.SomeFilter</filter-class>
<init-param>
<param-name>SomeInitParameter</param-name>
<param-value>4711</param-value>
</init-param>
</filter>
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>foo.bar.MyFilter</filter-class>
<init-param>
<param-name>MyInitParameter</param-name>
<param-value>0815</param-value>
</init-param>
<init-param>
<param-name>newparam1</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>newparam2</param-name>
<param-value>2</param-value>
</init-param>
</filter>
</web-app>
Use XPath Or:
Path|Path
From:
<paste path="//web-app/filter[1]/init-param" position="after" buffer="initParamBuffer"/>
To:
<paste path="//web-app/filter[1]/init-param|//web-app/filter[2]/init-param" position="after" buffer="initParamBuffer"/>
XPath is a Query language operating on the XML Infoset of XML documents. It can only return results or select nodes, but it cannot change the structure of the source XML document or modify it in any way.
A suitable language, designed especially for processing XML documentsand producing new XML documents, is XSLT.
The task specified in your question can be done in a very easy way using XSLT.
Please, provide a complete (but minimal) source XML document, the complete wanted result and specify any rules that the transformation should follow. Then many people will be able to give you correct and useful solutions.
I have struts2 web application. Right now I need embed with help of iframe some functionality from stand-alone servlet.
But according to following rule, servlet is never get calling.
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Unfortunately I cannot change it to /prefix/*
So does anybody know how to resolve it?
Filters are called in the order as they're definied in web.xml. I'd create a filter with a more specific url-pattern in the front of the Struts2 filter and then let this filter forward the request to the servlet in question instead of continuing the filter chain. E.g.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
request.getRequestDispatcher("/servletURL").forward(request, response);
}
Map this on the same url-pattern as the servlet, i.e. /servletURL and put it before the Struts2 filter in the web.xml.
Try looking at this: Struts 2 Web XML
There is a question: "Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)" which should ideally help. In theory you should be able to put your exception in this list, and map your servlet normally.
I won't comment on this design decision for the Struts 2 folks.
We are doing this with struts 2.1.6 defining the struts filter like this:
<filter><!-- struts filter -->
<filter-name>strutsFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>strutsFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
And our other Servlets like this:
<servlet-mapping>
<servlet-name>SomeOtherServlet</servlet-name>
<url-pattern>*.yo</url-pattern>
</servlet-mapping>
Is it possible to have the StripesDispatcher be the sole determiner of webserver urls by looking at the #UrlBinding annotations on action beans AND also having those action beans forward to pre-compiled JSPs / servlets WITHOUT needing to define and maintain <servlet> <servlet-mapping> pairs in web.xml? Basically, I just want to have to only maintain the #UrlBinding annotations as the sole determiners of available webapp paths.
Perhaps there is a way to point Jasper to where my servlets are and load them all up automatically without having to explicitly define each and every one?
The particular way in which this is achieved is not important, only that I leave the land of explicit servlet web.xml dependencies.
Maybe I don't understand your question, but I'll give it a go. AFAIK the only mapping you need in a Stripes app's web.xml to use #URLBinding as the 'source of truth' for URLs in your web-app:
<filter>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>com.your.action.beans.package</param-value>
</init-param>
<init-param>
<param-name>Extension.Packages</param-name>
<param-value>com.your.extension.packages</param-value>
</param-value>
</init-param>
</filter>
...
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
With this, there is no need to change anything in web.xml when you add/remove action beans and/or JSPs.