Struts

Different views on Struts2.0 Frameworks
Previous Home Next

 

There are different views by developers for Struts 2.0 Frameworks. Today Struts2.0 is one of the most used frameworks in Java/J2EE web based enterprise applications.

As struts2.0 provides a centralized controllers and Struts2.0 follows MVC-2 Design Pattern. So Struts2.0 is good option for web based applications. 

As it has clear separation for view, controller and model. The view developer have only focus on GUI ,The controller developer have focus on controller and networks securities and model developer have focus on writing business logic, so it is cost effective .The maintaining cost of struts2.0 application is less in term of money and as well as time.It also provide Struts2.0 tag libraries .Using these tag libraries a developer can make a jsp page easily. But as Struts2.0 takes more attention and need time to be expertise .So struts2.0 is note good option for small application.

 
Model-Action:- The model is implemented by the Struts 2 action component. But what exactly is the model The model is the internal state of the application. This state is composed of both the data model and the business logic.

MyAction.java

package org.r4r;
public class MyAction {
	private String name,password;
	public String execute(){
		return "success";
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}	
}

 View-Result:- The view is the presentation component of the MVC pattern. the result returns the page to the web browser. This page is the user interface these are commonly JSP pages, Velocity templates, or some other presentation-layer technology.

index.jsp

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

<s:form action="hello">
<s:textfield name="name" label="Name"/>
<s:submit value="Submit"/>
</s:form>

 Controller-FilterDispatcher:- The role of the controller is played by the Struts 2 FilterDispatcher. The FilterDispatcher class controlling the over all work flow in the struts2.0 framework.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

 

Previous Home Next