Home Struts Struts Struts2.2.1 Skinning example in Struts 2.2.1

Ask Questions?

View Latest Questions


 
 

Skinning example in Struts 2.2.1
Posted on: February 14, 2011 at 12:00 AM
Advertisement
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

login.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:head/>
<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>
</s:form>
</center>

home.jsp

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

SampleModel.java

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";
	}

}

SampleAction.java

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;
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if("".equals(model.getUserName()) || "".equals(model.getPassword())){
			return INPUT;
		}
		return SUCCESS;
	}
	
	@Override
	public SampleModel getModel() {
		// TODO Auto-generated method stub
		model=new SampleModel();
		return model;
	}
	
}

SampleInterfaceImp.java

<?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.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"
method="display">
<result name="input">login.jsp</result>
</action>

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

</package>

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

</struts>


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 :


DMCA.com