Struts2 Spring Hello World in Eclipse

Following example shows the integration of Struts2 ans Spring using ant in Eclipse
Using struts v-2.3.4.1 and spring v-3.2.0

File Structure
struts2 spring file structure

—index.jsp—

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




Hello World



   

Hello World From Struts2 - Spring integration



—Welcome.jsp—

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>




Hello World!


Action is executed

First Name: ${firstName}
Last Name: ${lastName}

—applicationContext.xml—



   
      
      
      
   

—User.java—

package org.apache.struts.helloworld.action;
public class User {
   private String firstName;
   private String lastName;

   public String execute()
   {
	   
	   //System.out.println("first\t"+getFirstName());
	   //System.out.println("last\t"+getLastName());
      return "success";
   }

   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }
}

—struts.xml—






	

	

        
        
		
			/index.jsp
		
		
		
		
        	 /Welcome.jsp
      	 
      
	


—web.xml—



Hello_World_Struts2_Ant
  
    index.jsp
  
  
  	
      
         org.springframework.web.context.ContextLoaderListener
      
   		 
   	
    
        struts2
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    

     
        struts2
        /*
    
    

OUTPUT:

output1
output2

Get the complete code with all the jars included. Enjoy

  • Hi, after reading this amazing paragraph i am also cheerful to share my experience here with mates.

%d bloggers like this: