Skinning example in Struts 2.2.1
Posted on: February 14, 2011 at 12:00 AM
In this tutorial you will learn about the struts skinning feature

Skinning example in Struts 2.2.1

An example of Skinning is given below


<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<center><h1>Please Login</h1>
<s:form action="home">
<s:textfield name="userName" key="userName" label="User Name"></s:textfield>
<s:textfield name="password" key="password" label="Password"></s:textfield>
<s:submit value="Register"></s:submit>


<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Home Page</title>
<body bgcolor="lightblue"><br><br><br><br><br>
<h1>Welcome <s:property value="userName"/></h1>

package net.roseindia.model;

public class SampleModel {
	private String userName;
	private String password;

	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;
	public String display(){
		return "input";


package net.roseindia.action;

import net.roseindia.model.SampleModel;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class SampleAction extends ActionSupport implements ModelDriven{
	private static final long serialVersionUID = 1L;
	SampleModel model;
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if("".equals(model.getUserName()) || "".equals(model.getPassword())){
			return INPUT;
		return SUCCESS;
	public SampleModel getModel() {
		// TODO Auto-generated method stub
		model=new SampleModel();
		return model;

<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />

<package name="roseindia" extends="struts-default">

<action name="login" class="net.roseindia.model.SampleModel"
<result name="input">login.jsp</result>

<action name="home" class="net.roseindia.action.SampleAction" >
<result name="success">home.jsp</result>
<result name="input">login.jsp</result>


<package name="userHtml" namespace="/wml" extends="roseindia"/>
<package name="userJsp" namespace="/jsp" extends="roseindia"/>


When you run this application it will display message as shown below:


Download Select Source Code

Related Tags for Skinning example in Struts 2.2.1 :



Advertisement null