Hi in this tutorial we will see the migration of a web application made in struts to spring mvc. Struts to Spring migration we will do step by step. Here I will share you step by step approach to migrate application from Struts to Spring using annotations.

Step 1: Replace struts libraries with spring libraries.

Firstly while migrating from struts to spring we have to replace our struts related libraries with spring libraries in lib folder.

I have mentioned basic libraries of both struts and spring for your clarification.

Struts basic libraries :

  1. struts.jar
  2. struts-legacy.jar
  3. etc.. 
Have you ever use :  Javadoc comment in Java

Spring basic libraries :


  1. standard.jar
  2. org.springframework.asm-4.0.1.RELEASE-A.jar
  3. org.springframework.beans-4.0.1.RELEASE-A.jar
  4. org.springframework.context-4.0.1.RELEASE-A.jar
  5. org.springframework.core-4.0.1.RELEASE-A.jar
  6. org.springframework.expression-4.0.1.RELEASE-A.jar
  7. org.springframework.web.servlet-4.0.1.RELEASE-A.jar
  8. org.springframework.web-4.0.1.RELEASE-A.jar
  9. etc..

Step 2: Change made to web.xml file for struts to spring migration

In this step we have to remove Action filter dispatcher for the web.xml and add Spring dipatcher servlet as Front controller
Work on new technology  : Create and manage cloud applications using Java

In Strut application web.xml look like as follows

<?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_3_0.xsd" id="WebApp_ID" version="3.0">  
  <display-name>Struts2MyFirstApp</display-name>  
  <filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>  
            org.apache.struts2.dispatcher.FilterDispatcher  
        </filter-class>  
    </filter>  

<filter-mapping>  
        <filter-name>struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
    <welcome-file-list>  
        <welcome-file>Login.jsp</welcome-file>  
    </welcome-file-list>  
</web-app>  

In Spring application web.xml look like as follows

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  
  <display-name>springApp</display-name>  
  <servlet>  
    <servlet-name>springApp</servlet-name>  
    <servlet-class>  
            org.springframework.web.servlet.DispatcherServlet  
        </servlet-class>  
    <load-on-startup>1</load-on-startup>  
  </servlet>  
  <servlet-mapping>  
    <servlet-name>springApp</servlet-name>  
    <url-pattern>/</url-pattern>  
  </servlet-mapping>  
</web-app>  

Step 3: Replace config files for struts to spring migration

Now replace all struts configuration files to spring configuration file as follows

In Struts applivation struts configuration file-

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE struts PUBLIC  
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
    "http://struts.apache.org/dtds/struts-2.0.dtd">  
   
<struts>  
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />  
    <constant name="struts.devMode" value="false" />  
    <constant name="struts.custom.i18n.resources" value="myapp" />  
   
    <package name="default" extends="struts-default" namespace="/">  
        <action name="login" class="com.geekonjavaonjava.struts2.login.LoginAction">  
            <result name="success">Welcome.jsp</result>  
            <result name="error">Login.jsp</result>  
        </action>  
    </package>  
</struts>  

In Spring application spring configuration file as follows

<?xml version="1.0" encoding="UTF-8"?>    
<beans xmlns="http://www.springframework.org/schema/beans"    
     xmlns:context="http://www.springframework.org/schema/context"    
     xmlns:p="http://www.springframework.org/schema/p"      
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
     xsi:schemaLocation="http://www.springframework.org/schema/beans    
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    
    http://www.springframework.org/schema/context    
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">    
        
     <context:component-scan base-package="com.geekonjavaonjava.spring.login.controller" />    
        
     <bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">    
        <property name="prefix">    
          <value>/WEB-INF/views/</value>    
        </property>    
        <property name="suffix">    
          <value>.jsp</value>    
        </property>    
      </bean>    
</beans>  <span style="font-family: Times New Roman;"><span style="white-space: normal;">  
</span></span>  
Here, <context:component-scan> tag is used, so that spring will load all the components from given package i.e. "com.geekonjavaonjava.spring.login.controller".

Use this in Struts2 : Get value of struts property tag into jsp variable

We can use different view resolver, here I have used InternalResourceViewResolver. In which prefix and suffix are used to resolve the view by prefixing and suffixing values to the object returned by ModelAndView in action class.

Step 4: JSP changes for struts to spring migration

While migration an application from struts to spring we need to change in jsp file as following

Firstly replace all tlds-

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>  
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>  
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>  
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

Replace these with following spring taglib's :

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>  
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>  

In Struts :

<html:form action="/addLogin" method="post">  

In Spring :

<form:form method="POST" commandName="loginForm" name="loginForm" action="login.do"> 
Here commandName is going to map with corresponding formbean for that jsp. Next we will see, how action is getting called with spring 4 annotations.

Step 5: Action class changes for struts to spring migration

Now following changes need to be done in action classes for struts to spring migration using annotations-

Struts Action:

package com.geekonjavaonjava.struts2.login;  
  
import com.opensymphony.xwork2.ActionSupport;  
  
/** 
 * @author geekonjava 
 * 
 */  
@SuppressWarnings("serial")  
public class LoginAction  extends ActionSupport{  
 private String username;  
    private String password;  
      
 public String execute() {  
     
        if (this.username.equals("geekonjava")   
                && this.password.equals("sweety")) {  
            return "success";  
        } else {  
         addActionError(getText("error.login"));  
            return "error";  
        }  
    }  
  
 public String getUsername() {  
  return username;  
 }  
  
 public void setUsername(String username) {  
  this.username = username;  
 }  
  
 public String getPassword() {  
  return password;  
 }  
  
 public void setPassword(String password) {  
  this.password = password;  
 }  
   
}  

Spring action

package com.geekonjavaonjava.spring.login.controller;  
  
import org.springframework.stereotype.Controller;  
import org.springframework.ui.ModelMap;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RequestMethod;  
  
/** 
 * @author GeekOnJava 
 * 
 */  
@Controller  
public class LoginController {  
   
 @RequestMapping(value="/login.do", method = RequestMethod.GET)  
 public String doLogin(ModelMap model, LoginForm loginForn) {  
 if (this.username.equals("geekonjava")   
                && this.password.equals("sweety")) {  
            model.addAttribute("message", "Login Success");  
        } else {  
            model.addAttribute("message", "Login Failure");  
        }  
         return "home";  
   
 }  
}  

Step 6: Validation changes for struts to spring migration 

In struts JSP file validation changes as follows

<%  
 ActionErrors actionErrors = (ActionErrors)request.getAttribute("org.apache.struts.action.ERROR");  
%>

In Spring JSP file as follows-

<form:errors path="*" cssClass="error" /> 
0

Add a comment

November 16th, 2021

Easy Steps to Add 301 Redirects to WordPress » Tell Me How - A Place for Technology Geekier: Before we try to learn how to add 301 redirects to WordPress, we need to understand what they really are. If you run your own website, it is a must to understand the ‘when’ and ‘how’ of using these.

Is Purefit Keto Beneficial For Weight Loss? » Tell Me How - A Place for Technology Geekier: The ketogenic diet is probably something that everyone interested in physical fitness might have heard about. In this diet plan, you eat lots of fat so that your body to burn even more fat.

The Best SEO Practices for Blogging » Tell Me How - A Place for Technology Geekier: How can SEO help your blog and vice versa? Today, we will give you some information about the best SEO Practices for Blogging.

json2view : Some important properties and types » Tell Me How - A Place for Technology Geekier: Here we see some important properties and types of json2view library which you can use in your applications. Just dive and enjoy the tutorials and code.

Yes You Can! How Millennials Can Actually Afford a House » Tell Me How - A Place for Technology Geekier: The consensus across the world is that Millennials can’t afford to buy houses. Sadly, this means that a lot of them have stopped trying.

However, along with this news, how are JDK builds available? Will they be free or paid? Before answering this, it's important to understand what a "valid" JDK for distribution actually means. In practical terms, there is only one set of source code for the JDK. 

The source code is hosted here.

Animated Recycler View is a library that allows you to animate a recycler view in your project like Google does it in its Google Play Store. Only the first visible items are animated there and you will see no animation when the recycler view scrolls up.

There are so many ways to make mobile apps ranging from direct platform specific development (using Java and Kotlin for Android, and ObjC and Swift for iOS), there’s React Native from Facebook, Electrode Native from Walmart, the Ionic framework, Unity for certain types of apps, and the flutter.io fr

This article looks at many categories of Java defects that Kotlin prevents in addition to null safety. Kotlin showed a surprising impact on productivity.

This article looks at many categories of Java defects that Kotlin prevents in addition to null safety.

Now you’re ready to multiply any number with 9 in 3 sec.

28 X 9 = ?

From Step 2, we’ve to subtract 28 with 3 :

28 – 3 = 25(this is your first part of your answer)

Now from Step 1, we’ve to multiply the unit place of 28 by 9 i.e. 8 X 9.

8 X 9 = 72 and we’ll take only unit place of answer i.e.

Today we’re going to learn CRUD example using Spring boot, Kotlin and AngularJS with WebJar. For this tutorial, nothing is assumed except some basic Java experience.

Today, the MVC pattern is used by well-known frameworks such as Ruby on Rails, Apple iOS Development, ASP.NET MVC, etc. While MVP is mostly used for ASP.NET Web Forms applications and MVVM is used by WPF, Caliburn, Silverlight, nRoute, and more.

Android Popup menu is really a good way to make your Android application more elegant and create a great UI.

There are several popular ORM database libraries out there (SQLDelight, GreenDAO, SugarORM) but we’re going to see top 10 Android database library and nearly every one uses reflection for critical database interactions. Back-end developers get things done, plain and simple.

What is BlockChain Advantage and Disadvantage?

Blockchain is a public record of transactions.

Top 3 Mobile Technology Trends in 2018

Here is my Top three technology trends you all should look out for in your endeavors in this new year 2018, which as always, will offer you loads of new opportunities to rock this world.

Top 5 Android Wear Library In 2018

Welcome to 2018. Happy New Year To All Of You.

If you’re planning to make your own Wear app then i can give you list of some great Android Wear library which you can use in 2018.

Android TextView is capable of showing text in your Android app and previously we discuss how to add rotating animation with TextView. This tutorial explains how to use MultiColor TextView in Android application.

This is a simple library to display text with multicolor.

A colleague approached me a while ago and asked me a question about Kotlin. What was this “Nothing type”, and what was it used for? I did not really have a good answer for him at the time.

Since then, I’ve found my answer.

Advanced Kotlin Tips on writing good Kotlin code and using what the language has to offer. There are many benefits of using Kotlin; it is concise, safe and most importantly it is 100% interoperable with Java. It also tries to solve some of the limitations of Java.

You are going to delete lots of lines of code! Yes, it is not a clickbait!

How do you pass your model between activities?

Serializable? EventBus / Otto ? Parcelable? Serializable = Reflection! Run Forest Run!!! It is terrible for Android performance.

Food Tracking Android Timeline View Example

Android Timeline View Library (Using RecyclerView) is simple implementation used to display view like Tracking of shipment/order, steppers etc.

Kotlin, my favourite programming language, has seen a fast adoption on platforms like Android or Server where the code is compiled to Java bytecode. However, as Kotlin also supports compilation to Javascript, the language is starting to receive attention in the Web ecosystem as well.

Justice League

Today i am going to share Review and Rating of recent release movie Justice League.  It’s better than Batman v Superman. But it’s more successful as a trailer for Aquaman or TheFlash than as a movie of its own.

Google Pixel 2 XL vs iPhone X: Find out Best phone

Google is challenging Apple with its second generation of smartphones, the Pixel 2.

You can easily get access to your system even when you do not remember the password. All you need to do in this situation is use the appropriate password recovery software and unlock your computer.

This post is a summary of first impressions of a few android related frameworks that we (Tell Me How Blog) tried out during a competences session recently.

Dagger

“Dagger constructs instances of your application classes and satisfies their dependencies.

The user interface often contains a lot of cluttered code primarily because of the complicated logic it needs to handle.

Thanks to the increasing number of security holes and increased number of cyber attacks, protecting your phone is more important than ever before.

Google knows this so they’ve begun rolling out Google Play Protect which was originally announced at I/O 2017.

Kotlin is all the rage lately. And while I do agree that the language is well thought out, it does have — as with everything else — its flaws.

These are my 10 favorite new Android animation libraries that have come out since October 2017. Some of them aren’t production ready yet, but you may have lots of fun using them. I hope you enjoy these.

Here they are in no particular order:

1.

Vega Scroll Layout is a lightweight animation flowlayout which fade and shrink the head itemView when scrolling.

Animation in Android is a best way to give a valuable UI in any application. So today i am going to how to implement Android rich path animator which can draw as you want animate much as you can.

What is Android Rich Path Animator?

This library define in simple three line:

Rich Android Path.

Contributors
Contributors
Popular Posts
Popular Posts
Archive
Labels
Labels
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.