Skip to main content

Posts

Showing posts from September 14, 2009

Spring’s AOP with Struts

Using Spring’s AOP with your Struts Application: To tackle cross-cutting you can use Spring interceptors To use Spring’s AOP in your Struts Applications you need to : 1. Create the interceptor. 2. Registor the interceptor. 3. Delclare interceptors. For example A sample logging interceptor package net.champ.example1.employee.interceptors; import org.springframework.aop.MethodBeforeAdvice; import java.lang.reflect.Method; public class LoggingInterceptor implements MethodBeforeAdvice { public void beforeMethod(Method method, Object[] objects, Object o) throws Throwable { System.out.println("logging before intersection"); } } This interceptor will execute the beforeMethod() before every intersection (We are using MethodBeforeAdvice). Here we are just printing a line but we can use it for anything we like. Next let us register the interceptor. Registering the interceptor in the Spring config file <?xml version="1.0" encoding="UTF-8...

Struts and Springs Integration

Integration using ActionSupport Integrating Struts with Spring doesn’t sound to be easy but if you follow this method you will find it quite simple and to add to this Spring provides you with org.springframework.web.struts.ActionSupport class. This class provides a method getWebApplicationContext() which you can use to obtain the Spring context. So you just have to extend Spring’s ActionSupport from your strut’s actions. Using ActionSupport to integrate Struts package net.champ.example1.actions; import java.io.IOException; import javax.servlet.*; import org.apache.struts.action.*; import org.springframework.context.ApplicationContext; import org.springframework.web.struts.ActionSupport; import net.champ.example1.beans.Employee; import net.champ.example1.business.EmpSearchService; public class SubmitSearch extends ActionSupport { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOExcep...