Monday, June 23, 2008

Configuring Spring for your Web App

Configuring Spring is pretty easy.

Add a listener:-

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

The ContextLoaderListener implements ServletContextListener.

You can also configure the xml which Spring should read:-

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/context/applicationContext-*.xml</param-value>
<!--
The following param-value should be used instead if we ever want to search for context files anywhere in the classpath
<param-value>/WEB-INF/classes/context/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
-->
</context-param>

Hope it helps,
Thanks.

Configuring struts for your Web Application

Configuring struts in your web application is pretty simple. You have to add a filter in you web.xml file:-


<filter>
<filter-name>struts</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>



And then provide appropriate mapping, like:-



<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


So, now every url will be passed through the struts filter.

Hope you find it useful.
Thanks.

Strtus, Spring and Hibernate

Now-a-days web applications are heavily using Struts, Spring and Hibernate for developing web apps.

Struts provide a MVC-based Action Framework for developing Web Applications.

Spring provides dependency injection and thereby can be used for managing the beans in your application.

Hibernate provides a simple yet very effective ORM tool. It simplifies most of the database related stuff and the developer has to only bother about business logic.

Thanks.