Monday, August 27, 2012

STRUTS2 Programs 013 field validator

EmailValidationAction.java
-------------------------------------------
package kites;

import com.opensymphony.xwork2.ActionSupport;

public class EmailValidationAction extends ActionSupport {

private String email;

public String getEmail() {

return email; }

public void setEmail(String email) {

this.email = email; }

@Override

public String execute() throws Exception {

// TODO Auto-generated method stub

return SUCCESS; }

}

------------------------------------------------------------------------------------------------------------------------------
EmailValidationAction-validation.xml
------------------------------------------------------------
<!DOCTYPE validators PUBLIC

"-//OpenSymphony Group//XWork Validator 1.0.2//EN"

"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="email">
<field-validator type="requiredstring">
<message>Email id is required</message>
</field-validator>
<field-validator type="email">
<message>Please enter valid email id.</message>
</field-validator>
</field>

</validators>

---------------------------------------------------------------------------------------------------------------------------------
index.jsp
--------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

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

<html>

<head><title>Email_Validator_Example</title><s:head/></head>

<body>Email_Validator_Example.....

<s:form action="emailvalidation.action">

<s:textfield name="email" label="Email-Id :"></s:textfield>

<s:submit></s:submit></s:form>

</body>

</html>

--------------------------------------------------------------------------------------------------------------------------------
struts.xml
----------------
<?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" />

<package name="kites" namespace="/" extends="struts-default">

<action name="emailvalidation" class="kites.EmailValidationAction">

<result name="input">index.jsp</result>

<result name="error">index.jsp</result>

<result>successJsp.jsp</result>

</action></package>

</struts>

-------------------------------------------------------------------------------------------------------------------------------
success.jsp
-------------------
<%@ page language="java"

contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

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

<html>

<head><title>Insert title here</title></head>

<body>Email-Id....

<s:property value="email"/></body>

</html>

-------------------------------------------------------------------------------------------------------------------------------
web.xml
-----------------
<?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>Struts 2</display-name>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>
</web-app>

------------------------------------------------------------------------------------------------------------------------------

Sunday, August 26, 2012

Android Example Edit Text

FieldDemo.java
-------------------------

package com.kites.fielddemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class FieldDemo extends Activity {

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

EditText fld=(EditText)findViewById(R.id.field);
fld.setText("Hello " +"World");
String st =fld.getText();

}
}

-------------------------------------------------------------------------------------------------------------------------------
main.xml
---------------

<?xml version="1.0" encoding="utf-8"?>
<EditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/field"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="false"
/>

Friday, August 24, 2012

JSTL CORE Tag Example c:out

coutexample.jsp
--------------------------------
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:out Tag Example</title>
</head>
<body>
<c:out value="${'<tag> , &'}"/>
</body>
</html>

Thursday, August 23, 2012

STRUTS2 Programs 012 Client side validation

index.jsp
----------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>Index Page</title>
</head>
<body><h3>Struts2_Client_Side_Validation_Example</h3>
<s:a href="registrationForm.action"><FONT color="green" >Go To Login Page..</FONT> </s:a>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------
package.properties
----------------------------------
requiredstring = ${getText(fieldName)} is required.
firstname = Student Name
password= Password


--------------------------------------------------------------------------------------------------------------------------------
RegistrationAction.java
---------------------------------------

package kites.action;

import kites.Model.RegistrationModel;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class RegistrationAction extends ActionSupport implements
ModelDriven<Object> {
RegistrationModel obRegModel;
public String execute() {
return SUCCESS;
}
@Override
public Object getModel() {
obRegModel = new RegistrationModel();
return obRegModel;
}
}

----------------------------------------------------------------------------------------------------------------------------------
RegistrationAction-validation.xml
------------------------------------------------------
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="firstname">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="stringlength">
<param name="minLength">5</param>
<param name="maxLength">15</param>
<param name="trim">true</param>
<message >Please enter Min %{minLength} character or Max %{maxLength} Character </message>
</field-validator>
</field>
</validators>
----------------------------------------------------------------------------------------------------------------------------
RegistrationForm.jsp
----------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>Registration Form</title></head>
<s:head/>
<body>
<h3 >Struts2_Client_Side_Validation_Example</h3>
<hr>
<font style="color: green;"> Registration Form</font>
<s:form action="registrationProcess.action" name="registration" method="post">
<s:textfield key="firstname" />
<s:password key="password"/>
<s:submit value="Registration"/>
</s:form>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------------------
RegistrationModel.java
--------------------------------------
package kites.Model;

import java.io.Serializable;
public class RegistrationModel implements Serializable
{
private String firstname;
private String password;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
--------------------------------------------------------------------------------------------------------------------------------
RegistrationSuccess.jsp
-------------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2 style="color: green">Hi,
<s:property value="firstname"/>
your welcome.</h2>
<h3 style="color: gray;">Login success.</h3>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------------------------
struts.xml
-------------------
<?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" />

<package name="kites" namespace="/" extends="struts-default">
<action name="registrationForm">
<result>/RegistrationForm.jsp</result>
</action>
<action name="registrationProcess" class="kites.action.RegistrationAction">
<result name="input">RegistrationForm.jsp</result>
<result name="error">RegistrationForm.jsp</result>
<result>RegistrationSuccess.jsp</result>
</action>
</package>
</struts>

--------------------------------------------------------------------------------------------------------------------------------
web.xml
----------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts2_Client_Side_Validation_Example</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>Struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

------------------------------------------------------------------------------------------------------------------------------------------------

Android Webservice Example

SOAP File form w3schools
---------------

POST /webservices/tempconvert.asmx HTTP/1.1
Host: www.w3schools.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/CelsiusToFahrenheit"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CelsiusToFahrenheit xmlns="http://tempuri.org/">
<Celsius>string</Celsius>
</CelsiusToFahrenheit>
</soap:Body>
</soap:Envelope>

-----------------------------------------------------------------------------------------------------------------------------
Android

Java Side
--------------

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

private static String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "CelsiusToFahrenheit";
private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";

public String invoke(String val){

String reply="";
// Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2);

// Use this to add parameters
request.addProperty("Celsius", val);

// Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;

try {

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

//call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);

// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;

// Get the first property
reply = result!=null?result.getProperty(0).toString():"0";



} catch (Exception e) {

e.printStackTrace();
}

}

-------------------------------------------------------------------------------------------------------------------------------------

Manifest Permission
--------------------------------

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Tuesday, August 21, 2012

Android Example 002 Button

main.xml
----------------

<?xml version="1.0" encoding="utf-8"?>
<Button       
    xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/bt"       
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello World, Now"
        >
</Button>

--------------------------------------------------------------------------------------------------------------------------
Now.java
--------------

package com.kites.buttontest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Date;

public class Now extends Activity implements View.OnClickListener {
    Button btn;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);   
        btn =(Button)findViewById(R.id.bt);
        btn.setOnClickListener(this);
        updateTime();
       
    }

    public void onClick(View view) {
        updateTime();
    }

    private void updateTime() {
        btn.setText(new Date().toString());
    }
}
--------------------------------------------------------------------------------------------------------------------------------

STRUTS 2 Programs 011 validation Interceptor

Login.jsp
-------------
<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Validation Interceptor Example</title>

<s:head />

</head>

<body bgcolor="lightblue">
<s:actionerror />
<s:form action="Validation">
<s:textfield name="userName" label="User Name"></s:textfield>
<br>
<s:password name="password" label="Password"></s:password>
<s:submit />
</s:form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------------------
LoginAction.java
---------------------------
package kites;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

    private static final long serialVersionUID = 525429611271529243L;

    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 execute() throws Exception {

        return SUCCESS;
    }

    public void validate() {

        if (getUserName().length() == 0) {

            addFieldError("userName", "");

        } else if (!getUserName().equals("Rose")) {

            addFieldError("userName", getText("userName.incorrect"));

        }

        if (getPassword().length() == 0) {

            addFieldError("password", getText("requiredpassword"));

        } else if (!getPassword().equals("RoseIndia")) {

            addFieldError("password", getText("password.incorrect"));
        }

    }

}
------------------------------------------------------------------------------------------------------------------------
LoginAction.properties
------------------------------------
username.incorrect = UserName is incorrect.

password.incorrect = Password is incorrect.

requiredstring = ${getText(fieldName)} is required.

requiredpassword = ${getText(fieldName)} should be more than 6 character.

------------------------------------------------------------------------------------------------------------------------------
struts.xml
------------------
<?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>

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



<action name="Validation" class="kites.LoginAction">

<interceptor-ref name="params">
    <param name="excludeParams">dojo\..*,^struts\..*</param>

</interceptor-ref>

<interceptor-ref name="validation">

    <param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>

<interceptor-ref name="workflow">

    <param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>

<result name="input">/Login.jsp</result>

<result name="success">/success.jsp</result>

</action>

</package>

</struts>
------------------------------------------------------------------------------------------------------------------------------
success.jsp
--------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Login Successful</title>

</head>

<body bgcolor="lightblue">

<h1>Login Successful</h1>

</body>

</html>
-----------------------------------------------------------------------------------------------------------------------------
web.xml
----------------
<?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>Struts 2</display-name>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>
</web-app>
-------------------------------------------------------------------------------------------------------------------------------------

Wednesday, August 15, 2012

Android Programs 001 TextView

main.xml
----------------


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv"   
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello"
    />
---------------------------------------------------------------------------------------------------------------------------
LabelDemo.java
---------------------------

package com.kites.labeldemo;

import android.app.Activity;
import android.os.Bundle;

public class LabelDemo extends Activity {
   
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        TextView tv=(TextView)findViewById(R.id.tv);
        tv.setText("View Text Data");
    }
}

-------------------------------------------------------------------------------------------------------------------------

STRUTS 2 programs 009 PreResultListener

error.jsp
--------------
<%@ taglib prefix="s" uri="/struts-tags" %><HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Error Page</TITLE>
</HEAD>

<BODY bgcolor="lightblue">
<center><h3>Sorry Wrong User Id</h3><h2> <s:property value="name"/></h2>
<h3>Please Input User Id kites</h3></center>
</BODY>
</HTML>

--------------------------------------------------------------------------------------------------------------------------------
home.jsp
--------------

<%@ taglib prefix="s" uri="/struts-tags" %><HTML>
<HEAD>
<TITLE> Home Page </TITLE>
</HEAD>

<body bgcolor="#F6E3CE">
<table border=1 colspacing=5 colspading=5 align=center>
<tr>
<td colspan=2 align="center">
<h1>You Are Welcome</h1>

</td>
</table>
</body>
</HTML>

-------------------------------------------------------------------------------------------------------------------------------
index.html
------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=loginPage.action">
</head>

<body bgcolor="lightgreen">
<center><font color="black" face="modern" size=6>Loading ...</font></center>
</body>
</html>

-------------------------------------------------------------------------------------------------------------------------------
login.jsp
------------

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

<head>
<title>Pre Result Listener Example</title>
</head>

<body bgcolor="#F6CEE3">
<s:form action="preResult">
<table border=1 colspacing=5 colspading=5 align=center>
<tr>
<td colspan=3 align=center>
<font color="#01DF01" face=arier>Please Enter Your Name</font>
</td>
</tr>
<tr>
<td colspan=3 align=center>
<s:actionerror />
<s:fielderror />
</td>
</tr>
<s:textfield name="name" label="Please Input Id"/>
<s:submit value="Login" align="center"/>
</table>
</s:form>

</body>
</html>
----------------------------------------------------------------------------------------------------------------------------
PreResultListenerExample.java
-------------------------------------------------

package com.kites;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.PreResultListener;

public class PreResultListenerExample extends ActionSupport{
    private static final long serialVersionUID = 1L;
    public String control=INPUT;
   
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
   
    public String execute() throws Exception {
         ActionContext context=ActionContext.getContext();
         ActionInvocation invocation=context.getActionInvocation();
         invocation.addPreResultListener(new PreResultListener() {
               public void beforeResult(ActionInvocation invocation, String resultCode){
                  // perform operation necessary before Result execution
                  System.out.println("Executing Action - "+invocation.getAction());
                     if(getName().equalsIgnoreCase("kites")){
                      System.out.println(getName());
                      invocation.setResultCode(SUCCESS);
                  }
                  else{
                      System.out.println("Going to error page "+getName());
                      invocation.setResultCode(ERROR);
                  }
                }
            });                
        return control;
     }
  }
 
---------------------------------------------------------------------------------------------------------------------------------
struts.xml
---------------

<?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" />

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

<action name="loginPage">
<result>/jsp/login.jsp</result>
</action>

<action name="preResult" class="com.kites.PreResultListenerExample">
<result name="error">/error.jsp</result>
<result name="input">/login.jsp</result>
<result name="success">/home.jsp</result>
</action>

</package>

</struts>
---------------------------------------------------------------------------------------------------------------------------------
web.xml
--------------
<?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>Struts 2</display-name>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>
</web-app>
--------------------------------------------------------------------------------------------------------------------------------

Saturday, August 4, 2012

Struts2 programs 008 Tiles Result

aboutUs.jsp
----------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<center><h1>About Us Page</h1></center>
------------------------------------------------------------------------------------------------------------------------
baseLayout.jsp
------------------------
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
<table border="0" cellpadding="2" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2" BGCOLOR="pink">
<tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td height="350" width="150" BGCOLOR="lightblue">
<tiles:insertAttribute name="menu" />
</td>
<td width="450" BGCOLOR="#CCFFCC">
<tiles:insertAttribute name="body" />
</td>
</tr>
<tr>
<td height="30" colspan="2" BGCOLOR="pink">
<tiles:insertAttribute name="footer" />
</td>
</tr>
</table>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------------
body.jsp
------------
<HTML>
<BODY bgcolor="pink">
<p>body/content of the page</p>
</BODY>
</HTML>
------------------------------------------------------------------------------------------------------------------------
contactUs.jsp
---------------------------
<h3><center>This is Contact Us Page</center></h3>
----------------------------------------------------------------------------------------------------------------------
footer.jsp
----------------
<div align="center">
Your Apps Footer Goes Here
</div>
---------------------------------------------------------------------------------------------------------------------
header.jsp
-----------------
<div align="center" style="font-weight:bold">
<font face="arier" size="6">Your Apps Header Goes Here</font>
</div>
--------------------------------------------------------------------------------------------------------------------
home.jsp
---------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<center>
<h1>Home Page of your Apps</h1>
<center>
---------------------------------------------------------------------------------------------------------------------
menu.jsp
-------------
<%@taglib uri="/struts-tags" prefix="s"%>

<h3 align="center" color="red">Menu</h3>
<ul><a href="<s:url action="hometilesAction"/>">Home</a><br></ul>
<ul><a href="<s:url action="contacttilesAction"/>">Contact Us</a><br></ul>
<ul><a href="<s:url action="aboutUstilesAction"/>">About Us</a><br></ul>
<ul><a href="<s:url action="tutorialtilesAction"/>">Struts2.2.1 Tutorials</a><br></ul>
-----------------------------------------------------------------------------------------------------------------------------
struts.xml
-----------------
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

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

<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>

<action name="*tilesAction" method="{1}" class="com.kites.TilesAction">
<result name="home" type="tiles">home</result>
<result name="aboutUs" type="tiles">aboutUs</result>
<result name="strutstutorial" type="tiles">tutorial</result>
<result name="contactUs" type="tiles">contact</result>
</action>

</package>
</struts>
------------------------------------------------------------------------------------------------------------------------------------
strutstutorial.jsp
---------------------------
<h3>
<center>
<a href="#">Struts2 tutorials</a>
</center>
</h3>
----------------------------------------------------------------------------------------------------------------------------
tiles.xml
----------------
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

<definition name="baseLayout" template="/layouts/baseLayout.jsp">

<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/layouts/header.jsp"/>
<put-attribute name="menu" value="/layouts/menu.jsp"/>
<put-attribute name="body" value="/layouts/bodyPart.jsp"/>
<put-attribute name="footer" value="/layouts/footer.jsp"/>

</definition>

<definition name="home" extends="baseLayout">
<put-attribute name="title" value="Home"/>
<put-attribute name="body" value="/pages/home.jsp"/>
</definition>

<definition name="aboutUs" extends="baseLayout">
<put-attribute name="title" value="AboutUs"/>
<put-attribute name="body" value="/pages/aboutUs.jsp"/>
</definition>

<definition name="tutorial" extends="baseLayout">
<put-attribute name="title" value="StrutsTutorial"/>
<put-attribute name="body" value="/pages/strutstutorial.jsp"/>
</definition>

<definition name="contact" extends="baseLayout">
<put-attribute name="title" value="contactUs"/>
<put-attribute name="body" value="/pages/contactUs.jsp"/>
</definition>

</tiles-definitions>

-----------------------------------------------------------------------------------------------------------------------------------
TilesAction.java
----------------------------
package com.kites;

import com.opensymphony.xwork2.ActionSupport;

public class TilesAction extends ActionSupport {

    private static final long serialVersionUID = -2613425890762568273L;

    public String home()
    {
        return "home";       
    }
   
    public String aboutUs()
    {
        return "aboutUs";       
    }

    public String tutorial()
    {
        return "strutstutorial";       
    }

    public String contact()
    {
        return "contactUs";       
    }

    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        return home();
    }
}   
------------------------------------------------------------------------------------------------------------
web.xml
--------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Struts Tiles Example</display-name>

<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>
------------------------------------------------------------------------------------------------------------------------------

STRUTS 2 programs 007 Plain Text Result

index.jsp
----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Index Page</TITLE>
</HEAD>
<BODY bgcolor="lightblue"><br clear="all"/><br clear="all"/>
<h2>Index</h2>
<font color="green" face="modern" size="4">
<ul>
<li>View the <a href="rawData.action">JSP</a> File In Plain Text</li><br clear="all"/>
<li>View the <a href="textData.action">Text</a> File In Plain Text</li>
</ul>
</font>

</BODY>
</HTML>
-------------------------------------------------------------------------------------------------------------------------
testJSP.jsp
-----------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Plain Text Example</title>
</head>

<body bgcolor="lightblue">
<font size="6" face="modern">This is Plain Text Demo</font>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------
struts.xml
-----------------
<?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" />

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

<action name="rawData" >

<result type="plainText">
<param name="location">/testJSP.jsp</param>
<param name="charSet">UTF-8</param>
</result>

</action>

<action name="textData" >

<result type="plainText">
<param name="location">/testText.txt</param>
<param name="charSet">UTF-8</param>
</result>

</action>

</package>

</struts>
----------------------------------------------------------------------------------------------------------------------
web.xml
-------------------
<?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>Struts 2</display-name>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>
</web-app>
---------------------------------------------------------------------------------------------------------------------------
testText.txt
---------------------
Hi This is test raw file you are looking on the Browser ....................
----------------------------------------------------------------------------------------------------------------------