Spring Framework

Spring Projects

Spring Project 1

Example of Struts 2.x ,Spring 2.5 integration
Previous Home Next

Introduction: This tutorial provide the example to integrate between struts2 and spring framework.

Technology use to run this source code:

  1. Spring2.5 jar file
  2. Eclips Id
  3. Tomcat Server

Source Code

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Struts2Example14</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloWorldClass" class="org.r4r.HelloWorld" >
	
</bean>
</beans>

structs.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="default" extends="struts-default">
<action name="helloWorld" class="helloWorldClass">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

HelloWorld.java

package org.r4r;

public class HelloWorld {
private String message;
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String execute() {
return "success";
}
}

index.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<s:form action="helloWorld">
<s:textfield name="message" label="Name"></s:textfield>
<s:submit></s:submit>
</s:form>

success.jsp

<%@taglib uri="/struts-tags" prefix="s"%>

Welcome, <s:property value="message"/>

output

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: