Hi i am facing a problem with struts2 when using the following code in web.xml
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
when i configured like above all my jstl tags in all jsp were not working
but when i remove
<dispatcher>FORWARD</dispatcher>
from the above configuration they are working
but i requried <dispatcher>FORWARD</dispatcher>
for url rewriting
Can any one suggest me what i have to do to solve my problem
Try using:
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
instead of FilterDispatcher, that is deprecated. More info here.
Related
We recently started integrating spring-session in our project. This is a SOA based application and have some logic implementations to manage sessions.
HttpSessionListener which we use to log out the sessions in case of timeout and monitored through sessionDestroyed(HttpSessionEvent httpSessionEvent).
ServletRequestListener which we use to manage HTTP session invalidations. This is implemented in requestDestroyed(ServletRequestEvent servletRequestEvent) method.
For item #1, I found an article here, which describes the use of SessionEventHttpSessionListenerAdapter as supported by Spring Session. And have this configuration added in my session.xml.
<context:annotation-config/>
<bean class="org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration"/>
<bean class="org.springframework.session.web.http.SessionEventHttpSessionListenerAdapter">
<constructor-arg>
<list>
<bean class="xxx.xxx.xxx.xxx.xxx.xxx.MyHttpSessionListener"/>
</list>
</constructor-arg>
</bean>
Also added below configuration in my deployment descriptor (e.g. web.xml)
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
After some debugging, I have noticed that my HttpSessionListener is using the session provided by spring session.
However, for item #2, using ServletRequestListener implementation, I could not find a way to migrate it to spring session. It is still using the session provided by the container.
Is there a corresponding adapter, like SessionEventHttpSessionListenerAdapter, intended for ServletRequestListener? Is this supported by Spring Session? What other options do I have to get our functionality working with spring session?
I ended up using custom Filter to manage HTTP session invalidation. Modified the web.xml with the following entries in sequence:
(a) Register springSessionRepositoryFilter
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(b) Add requestContextFilter
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(c) Add custom filter
<filter>
<filter-name>myCustomServletRequestFilter</filter-name>
<filter-class>com.xxx.xxx.xxx.servlet.filter.MyCustomServletRequestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myCustomServletRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(d) Load spring session context
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application-context.xml</param-value>
</context-param>
All HTTP requests are now using spring session.
Normally I would have added org.springframework.web.filter.DelegatingFilterProxy with a snippet like this to web.xml:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
But with Servlet 3.0 Container and Jetty, I've removed web.xml. I'm trying to add DelegatingFilterProxy to Jetty's launch with:
context.addFilter(DelegatingFilterProxy.class, "/*", EnumSet.allOf(DispatcherType.class));
but I get error:
No bean named 'org.springframework.web.filter.DelegatingFilterProxy-100555887' is defined
How am I supposed to create and add this filter?
context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class));
seems to be the correct syntax.
I need to integrate pretty faces with my jsf 2.0, primefaces application, but its giving some troubles.
As mentioned in the getting started i placed following in my web.xml, added the required jar in the lib folder
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
other items in my web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name>
<param-value>false</param-value>
</context-param>
But i am getting following Error:
Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":init-param}' is expected
If i remove <async-supported> from the project builds, project compiles but the mapping doesnt work.
pretty-config.xml is same as in the getting started.
Do i need to mention in my web.xml the name/path of the mapping file i.e pretty-config.xml?
EDIT:
I am using Glassfish server 3.
It is very important to check the version attribute you are using in your web.xml. If you have version="2.5" set, you have to add this to your web.xml:
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Please not that <async-supported>true</async-supported> is NOT set here, because it is only supported in Servlet 3.0.
If you have version="3.0" set in your web.xml, you don't have to add anything to your web.xml. In this case PrettyFaces automatically registers the filter using the web-fragment.xml that is included in prettyfaces-jsf2.jar.
You don't have to specify the location of pretty-config.xml anywhere. Just place it in your WEB-INF folder and PrettyFaces will find it.
You should also add one mapping to your pretty-config.xml, so you can check if everything works correctly. If you have for example a page that you typically access using an URL like:
http://localhost:8080/myapp/faces/login.xhtml
Then you can add this mapping:
<url-mapping id="login">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
Now you should be able to access the page using this link:
http://localhost:8080/myapp/login
Using convention-plugin seems really easy but im not able to make it work :(
I'm using struts2 version 2.2.3
I have a package named com.medicis.actions with a UserAction extending ActionSupport.
I don't have any struts.xml file
I have the convention-plugin depency set on my maven configuration (i also checked the generated war file)
There is my web.xml :
<display-name>Starter</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- Filters -->
<filter>
<filter-name>action2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>action2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<!-- Welcome file lists -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I tried with and without the init param for the action2 filter:
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.medicis.actions</param-value>
</init-param>
I have this property set on my struts.propertie file :
struts.action.extension=action
Still i'm unable to launch my action using localhost:8080/starter/user.action :
There is no Action mapped for namespace / and action name user
I really don't know what's going wrong, I even downloaded a simple example without any result either.
Could it be a configuration problem due to eclipse, m2eclipse, maven wtp or geronimo ???
If you need more information just tell me and i'll provide you that asap.
Create struts.properties in "src" folder
Copy and paste code from below:
struts.convention.package.locators = actions
struts.convention.action.suffix = Controller
struts.convention.action.mapAllMatches = true
Create class called IndexController in com.example.actions
Copy and paste code from below:
package com.example.actions;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import com.opensymphony.xwork2.ActionSupport;
public class UserController extends ActionSupport {
public String index(){
return SUCCESS
}
}
You also need to create jsp file in WEB-INF/content/user/index.jsp
How can you have a grails application as well as other servlets defined in your web.xml?
I want to have it so that some url patterns are handled by a servlet while all others are handled by Sitemesh/grails.
The default configuration of web.xml generated by grails is:
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>grailsWebRequest</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>urlMapping</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>grails</servlet-name>
<servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
I then added the configuration to web.xml for my 2nd servlet:
<servlet>
<servlet-name>Tracepoints</servlet-name>
<servlet-class>com.mydomain.Tracepoints</servlet-class>
<init-param>
<param-name>hostName</param-name>
<param-value>http://www.mydomain.com/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Tracepoints</servlet-name>
<url-pattern>*.tpoints</url-pattern>
</servlet-mapping>
But the above doesn't allow me to access my non grails servlet (with the url: domain.com/hello.tpoints) and trying it gets me a 404. I do know that the servlet's class files are deployed with the war because they exist in WEB-INF/classes directory.
You need to give the Grails servlet a more specific url-pattern in the mapping, e.g. /grails/* or *.grails or so (you're free to choose), so that only the URL's matching those patterns invokes the Grails servlet.