Append.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 prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Append Tag Example</title>
</head>
<body>
<h1>Struts 2 Append tag example</h1>
Combine ArrayList1 and ArrayList2 into a single iterator.
<s:append id="AppendList">
<s:param value="%{list1}" />
<s:param value="%{list2}" />
</s:append>
<s:iterator value="%{#AppendList}">
<li><s:property /></li>
</s:iterator>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------
index.jsp
-------------
<body>
<a href="AppendTag.action">Append Control Tag Example</a>
</body>
--------------------------------------------------------------------------------------------------------------------------
AppendTag.java
----------------------
package kites;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import org.apache.struts2.util.AppendIteratorFilter;
public class AppendTag extends ActionSupport {
private List<String> list1 = new ArrayList<String>();
private List<String> list2 = new ArrayList<String>();
public String execute() throws Exception {
list1.add("USER1");
list1.add("USER2");
list1.add("USER3");
list2.add("user1");
list2.add("user2");
list2.add("user3");
return SUCCESS;
}
public List<String> getList1() {
return list1;
}
public List<String> getList2() {
return list2;
}
}
--------------------------------------------------------------------------------------------------------------------------
struts.xml
---------------
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" namespace="/" extends="struts-default">
<action name="AppendTag" class="kites.AppendTag">
<result name="success">/Append.jsp</result>
</action>
</package>
</struts>
--------------------------------------------------------------------------------------------------------------------------
Monday, December 10, 2012
Friday, October 5, 2012
Android Call Blocking
Android Manifest
---------------------------------
<receiver android:name="com.kites.profile.util.PhoneCallReceiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
------------------------------------------------------------------------------------------
PhoneCallReceiver.java
--------------------------------
package com.kites.profile.util;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
public class PhoneCallReceiver extends BroadcastReceiver {
boolean active = true;
String replymsg = "";
Context context = null;
private static final String TAG = "Phone call";
private ITelephony telephonyService;
TelephonyManager telephony = null;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");
telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
telephony.listen(customPhoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
public void endCall() {
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.silenceRinger(); //comment this for android 2.3 and above
telephonyService.endCall();
// s
} catch (Exception e) {
e.printStackTrace();
}
}
public class CustomPhoneStateListener extends PhoneStateListener {
private static final String TAG = "CustomPhoneStateListener";
public void onCallStateChanged(int state, String incomingNumber) {
Log.v(TAG, "WE ARE Receiving!");
Log.v(TAG, incomingNumber);
Log.v(TAG, incomingNumber); if (active) {
endCall();
sendSMS(incomingNumber, replymsg);
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "RINGING");
break;
}
}
public void sendSMS(String no, String msg) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, null, null);
}
}
}
--------------------------------------------------------------------------------------------
ITelephony.aidl
---------------------------
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
---------------------------------
<receiver android:name="com.kites.profile.util.PhoneCallReceiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
------------------------------------------------------------------------------------------
PhoneCallReceiver.java
--------------------------------
package com.kites.profile.util;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
public class PhoneCallReceiver extends BroadcastReceiver {
boolean active = true;
String replymsg = "";
Context context = null;
private static final String TAG = "Phone call";
private ITelephony telephonyService;
TelephonyManager telephony = null;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");
telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
telephony.listen(customPhoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
public void endCall() {
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.silenceRinger(); //comment this for android 2.3 and above
telephonyService.endCall();
// s
} catch (Exception e) {
e.printStackTrace();
}
}
public class CustomPhoneStateListener extends PhoneStateListener {
private static final String TAG = "CustomPhoneStateListener";
public void onCallStateChanged(int state, String incomingNumber) {
Log.v(TAG, "WE ARE Receiving!");
Log.v(TAG, incomingNumber);
Log.v(TAG, incomingNumber); if (active) {
endCall();
sendSMS(incomingNumber, replymsg);
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "RINGING");
break;
}
}
public void sendSMS(String no, String msg) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, null, null);
}
}
}
--------------------------------------------------------------------------------------------
ITelephony.aidl
---------------------------
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
Thursday, September 27, 2012
Checking Status Of Remote Server
This function will help you identify the status of a remote server
public static boolean check(String ip,int port){
boolean flag=false;
try {
Socket soc= new Socket();
SocketAddress socketAddress = new InetSocketAddress(ip, port);
soc.connect(socketAddress, 5000); // 5 second timeout
flag=true;
} catch (Exception e) {
// TODO: handle exception
flag=false;
}
return flag;
}
public static boolean check(String ip,int port){
boolean flag=false;
try {
Socket soc= new Socket();
SocketAddress socketAddress = new InetSocketAddress(ip, port);
soc.connect(socketAddress, 5000); // 5 second timeout
flag=true;
} catch (Exception e) {
// TODO: handle exception
flag=false;
}
return flag;
}
Saturday, September 22, 2012
Line Graph Using Google
Chart.html
I got this piece of code from google api site .
It is pretty handy in generating a line graph
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses','Profit'],
['2004', 1000, 400,1000-400],
['2005', 1170, 460,1170-460],
['2006', 660, 1120,660-1120],
['2007', 1030, 540,1030-540],
['2008', 1030, 540,1030-540]
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
I got this piece of code from google api site .
It is pretty handy in generating a line graph
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses','Profit'],
['2004', 1000, 400,1000-400],
['2005', 1170, 460,1170-460],
['2006', 660, 1120,660-1120],
['2007', 1030, 540,1030-540],
['2008', 1030, 540,1030-540]
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Thursday, September 20, 2012
DSA Batch Verification Algorithm
GenSig.java
----------------------------
import java.io.*;
import java.security.*;
class GenSig {
public static void main(String[] args) {
// args=new String[]{"LabelDemo.java"};
/* Generate a DSA signature */
if (args.length != 1) {
System.out.println("Usage: GenSig nameOfFileToSign");
}
else try{
/* Generate a key pair */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
PrivateKey priv = pair.getPrivate();
PublicKey pub = pair.getPublic();
/* Create a Signature object and initialize it with the private key */
Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
dsa.initSign(priv);
/* Update and sign the data */
FileInputStream fis = new FileInputStream(args[0]);
BufferedInputStream bufin = new BufferedInputStream(fis);
byte[] buffer = new byte[1024];
int len;
while (bufin.available() != 0) {
len = bufin.read(buffer);
dsa.update(buffer, 0, len);
};
bufin.close();
/* Now that all the data to be signed has been read in,
generate a signature for it */
byte[] realSig = dsa.sign();
/* Save the signature in a file */
FileOutputStream sigfos = new FileOutputStream("sig");
sigfos.write(realSig);
sigfos.close();
/* Save the public key in a file */
byte[] key = pub.getEncoded();
FileOutputStream keyfos = new FileOutputStream("suepk");
keyfos.write(key);
keyfos.close();
System.out.println("Signature Generated");
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
};
}
----------------------------------------------------------------------------
Usage: GenSig nameOfFileToSign
-------------------------------------------------------------------------------------------------------------------------
VerSig.java
--------------------
import java.io.*;
import java.security.*;
import java.security.spec.*;
class VerSig {
public static void main(String[] args) {
/* Verify a DSA signature */
// args =new String[]{"suepk","sig","1"};//LabelDemo.java"};
if (args.length != 3) {
System.out.println("Usage: VerSig publickeyfile signaturefile datafile");
}
else try{
/* import encoded public key */
FileInputStream keyfis = new FileInputStream(args[0]);
byte[] encKey = new byte[keyfis.available()];
keyfis.read(encKey);
keyfis.close();
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
/* input the signature bytes */
FileInputStream sigfis = new FileInputStream(args[1]);
byte[] sigToVerify = new byte[sigfis.available()];
sigfis.read(sigToVerify );
sigfis.close();
/* create a Signature object and initialize it with the public key */
Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
sig.initVerify(pubKey);
/* Update and verify the data */
FileInputStream datafis = new FileInputStream(args[2]);
BufferedInputStream bufin = new BufferedInputStream(datafis);
byte[] buffer = new byte[1024];
int len;
while (bufin.available() != 0) {
len = bufin.read(buffer);
sig.update(buffer, 0, len);
};
bufin.close();
boolean verifies = sig.verify(sigToVerify);
System.out.println("signature verifies: " + verifies);
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
};
}
}
--------------------------------------------------------------------------------------------------------
Usage: VerSig publickeyfile signaturefile datafile
---------------------------------------------------------------------------------
----------------------------
import java.io.*;
import java.security.*;
class GenSig {
public static void main(String[] args) {
// args=new String[]{"LabelDemo.java"};
/* Generate a DSA signature */
if (args.length != 1) {
System.out.println("Usage: GenSig nameOfFileToSign");
}
else try{
/* Generate a key pair */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
PrivateKey priv = pair.getPrivate();
PublicKey pub = pair.getPublic();
/* Create a Signature object and initialize it with the private key */
Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
dsa.initSign(priv);
/* Update and sign the data */
FileInputStream fis = new FileInputStream(args[0]);
BufferedInputStream bufin = new BufferedInputStream(fis);
byte[] buffer = new byte[1024];
int len;
while (bufin.available() != 0) {
len = bufin.read(buffer);
dsa.update(buffer, 0, len);
};
bufin.close();
/* Now that all the data to be signed has been read in,
generate a signature for it */
byte[] realSig = dsa.sign();
/* Save the signature in a file */
FileOutputStream sigfos = new FileOutputStream("sig");
sigfos.write(realSig);
sigfos.close();
/* Save the public key in a file */
byte[] key = pub.getEncoded();
FileOutputStream keyfos = new FileOutputStream("suepk");
keyfos.write(key);
keyfos.close();
System.out.println("Signature Generated");
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
};
}
----------------------------------------------------------------------------
Usage: GenSig nameOfFileToSign
-------------------------------------------------------------------------------------------------------------------------
VerSig.java
--------------------
import java.io.*;
import java.security.*;
import java.security.spec.*;
class VerSig {
public static void main(String[] args) {
/* Verify a DSA signature */
// args =new String[]{"suepk","sig","1"};//LabelDemo.java"};
if (args.length != 3) {
System.out.println("Usage: VerSig publickeyfile signaturefile datafile");
}
else try{
/* import encoded public key */
FileInputStream keyfis = new FileInputStream(args[0]);
byte[] encKey = new byte[keyfis.available()];
keyfis.read(encKey);
keyfis.close();
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
/* input the signature bytes */
FileInputStream sigfis = new FileInputStream(args[1]);
byte[] sigToVerify = new byte[sigfis.available()];
sigfis.read(sigToVerify );
sigfis.close();
/* create a Signature object and initialize it with the public key */
Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
sig.initVerify(pubKey);
/* Update and verify the data */
FileInputStream datafis = new FileInputStream(args[2]);
BufferedInputStream bufin = new BufferedInputStream(datafis);
byte[] buffer = new byte[1024];
int len;
while (bufin.available() != 0) {
len = bufin.read(buffer);
sig.update(buffer, 0, len);
};
bufin.close();
boolean verifies = sig.verify(sigToVerify);
System.out.println("signature verifies: " + verifies);
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
};
}
}
--------------------------------------------------------------------------------------------------------
Usage: VerSig publickeyfile signaturefile datafile
---------------------------------------------------------------------------------
Tuesday, September 18, 2012
Struts2 Programs Tags 015 if elseif else tag
IfControlTag.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 prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:set name="Name" value="%{'Gyan'}" />
<s:if test="%{#Name=='Singh'}">You Working with--
<div><s:property value="%{#Name}" /></div>
<div>Your Name is Gyan</div>
</s:if>
<s:elseif test="%{#Name=='Gyan'}">You Working with--
<div><s:property value="%{#Name}" /></div>
<div>My Name is Gyan</div>
</s:elseif>
<s:else>for false condition
<div>Your Name is Not Specified</div>
</s:else>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------
index.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 prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>If Control Tag</title>
</head>
<body>
<ul>
<li><a href="IfControlTag.jsp">IF Control Tag Example</a></li>
</ul>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------
Result.java
-------------------
package kites;
import com.opensymphony.xwork2.ActionSupport;
public class Result extends ActionSupport{
public String execute() throws Exception {
return SUCCESS;
}
}
-----------------------------------------------------------------------------------------------------------------------
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" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="kites" extends="struts-default" namespace="/">
<action name="Result" class="kites.Result" >
<result name="SUCCESS">/IfControlTag.jsp</result>
</action>
</package>
</struts>
---------------------------------------------------------------------------------------------------------------------
------------------------
<%@ 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 prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:set name="Name" value="%{'Gyan'}" />
<s:if test="%{#Name=='Singh'}">You Working with--
<div><s:property value="%{#Name}" /></div>
<div>Your Name is Gyan</div>
</s:if>
<s:elseif test="%{#Name=='Gyan'}">You Working with--
<div><s:property value="%{#Name}" /></div>
<div>My Name is Gyan</div>
</s:elseif>
<s:else>for false condition
<div>Your Name is Not Specified</div>
</s:else>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------
index.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 prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>If Control Tag</title>
</head>
<body>
<ul>
<li><a href="IfControlTag.jsp">IF Control Tag Example</a></li>
</ul>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------
Result.java
-------------------
package kites;
import com.opensymphony.xwork2.ActionSupport;
public class Result extends ActionSupport{
public String execute() throws Exception {
return SUCCESS;
}
}
-----------------------------------------------------------------------------------------------------------------------
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" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="kites" extends="struts-default" namespace="/">
<action name="Result" class="kites.Result" >
<result name="SUCCESS">/IfControlTag.jsp</result>
</action>
</package>
</struts>
---------------------------------------------------------------------------------------------------------------------
Tuesday, September 11, 2012
Android Programs 005 RadioButton
RadioButtonDemo.java
--------------------------------------
package com.kites.radiotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
public class RadioButtonDemo extends Activity
implements RadioGroup.OnCheckedChangeListener{
RadioGroup rg;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
rg=(RadioGroup)findViewById(R.id.rg);
rg.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group,
int checkedId) {
if (group==rg) {
if (checkedId==R.id.r1) {
}
else if (checkedId==R.id.r2) {
}
else if (checkedId==R.id.r3) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id="@+id/rg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioButton android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1" />
<RadioButton android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2" />
<RadioButton android:id="@+id/r3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3" />
</RadioGroup>
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------
package com.kites.radiotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
public class RadioButtonDemo extends Activity
implements RadioGroup.OnCheckedChangeListener{
RadioGroup rg;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
rg=(RadioGroup)findViewById(R.id.rg);
rg.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group,
int checkedId) {
if (group==rg) {
if (checkedId==R.id.r1) {
}
else if (checkedId==R.id.r2) {
}
else if (checkedId==R.id.r3) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id="@+id/rg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioButton android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1" />
<RadioButton android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2" />
<RadioButton android:id="@+id/r3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3" />
</RadioGroup>
-------------------------------------------------------------------------------------------------------------------------------
Monday, September 3, 2012
STRUTS2 Examples 014 Non Field Validators
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 </h1><s:property value="userName"/>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------------
login.jsp
-------------
<%@ taglib prefix="s" uri="/struts-tags"%>
<link href="<s:url value="css/style.css"/>" rel="stylesheet"
type="text/css" />
<s:actionerror />
<center>
<h1>Please Login</h1>
</center>
<s:form method="POST" action="nonField">
<s:textfield name="userName" label="User Name" />
<s:textfield name="password" label="Password" />
<s:submit label="Submit" />
</s:form>
----------------------------------------------------------------------------------------------------------------------------------
LoginAction.java
---------------------------
package com.kites.action;
import com.kites.model.LoginModel;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class LoginAction extends ActionSupport implements
ModelDriven<LoginModel> {
private static final long serialVersionUID = 1L;
LoginModel model;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if (!model.getUserName().equals("")) {
return SUCCESS;
}
return INPUT;
}
@Override
public LoginModel getModel() {
// TODO Auto-generated method stub
model = new LoginModel();
return model;
}
}
---------------------------------------------------------------------------------------------------------------------------
LoginAction-validation.xml
-------------------------------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Home Page</title>
</head>
<body bgcolor="lightblue"><br><br><br><br><br>
<h1>Welcome </h1><s:property value="userName"/>
</body>
</html><!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<validator type="expression">
<param name="fieldName">userName</param>
<message>You must enter the User Name</message>
</validator>
<validator type="expression">
<param name="fieldName">password</param>
<message>You must enter Password</message>
</validator>
</validators>
--------------------------------------------------------------------------------------------------------------------------------
LoginModel.java
----------------------------
package com.kites.model;
import java.io.Serializable;
public class LoginModel implements Serializable {
private static final long serialVersionUID = 1L;
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";
}
}
-------------------------------------------------------------------------------------------------------------------------------
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.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />
<package name="kites" namespace="/" extends="struts-default">
<action name="login" method="display" class="com.kites.model.LoginModel">
<result name="input">login.jsp</result>
</action>
<action name="nonField" class="com.kites.action.LoginAction">
<result name="success">home.jsp</result>
<result name="input">login.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>
-------------------------------------------------------------------------------------------------------------------------------
--------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Home Page</title>
</head>
<body bgcolor="lightblue"><br><br><br><br><br>
<h1>Welcome </h1><s:property value="userName"/>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------------
login.jsp
-------------
<%@ taglib prefix="s" uri="/struts-tags"%>
<link href="<s:url value="css/style.css"/>" rel="stylesheet"
type="text/css" />
<s:actionerror />
<center>
<h1>Please Login</h1>
</center>
<s:form method="POST" action="nonField">
<s:textfield name="userName" label="User Name" />
<s:textfield name="password" label="Password" />
<s:submit label="Submit" />
</s:form>
----------------------------------------------------------------------------------------------------------------------------------
LoginAction.java
---------------------------
package com.kites.action;
import com.kites.model.LoginModel;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class LoginAction extends ActionSupport implements
ModelDriven<LoginModel> {
private static final long serialVersionUID = 1L;
LoginModel model;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if (!model.getUserName().equals("")) {
return SUCCESS;
}
return INPUT;
}
@Override
public LoginModel getModel() {
// TODO Auto-generated method stub
model = new LoginModel();
return model;
}
}
---------------------------------------------------------------------------------------------------------------------------
LoginAction-validation.xml
-------------------------------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Home Page</title>
</head>
<body bgcolor="lightblue"><br><br><br><br><br>
<h1>Welcome </h1><s:property value="userName"/>
</body>
</html><!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<validator type="expression">
<param name="fieldName">userName</param>
<message>You must enter the User Name</message>
</validator>
<validator type="expression">
<param name="fieldName">password</param>
<message>You must enter Password</message>
</validator>
</validators>
--------------------------------------------------------------------------------------------------------------------------------
LoginModel.java
----------------------------
package com.kites.model;
import java.io.Serializable;
public class LoginModel implements Serializable {
private static final long serialVersionUID = 1L;
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";
}
}
-------------------------------------------------------------------------------------------------------------------------------
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.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />
<package name="kites" namespace="/" extends="struts-default">
<action name="login" method="display" class="com.kites.model.LoginModel">
<result name="input">login.jsp</result>
</action>
<action name="nonField" class="com.kites.action.LoginAction">
<result name="success">home.jsp</result>
<result name="input">login.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>
-------------------------------------------------------------------------------------------------------------------------------
Sunday, September 2, 2012
Android Examples 004 CheckBox
CheckBoxDemo.java
------------------------------------
package com.kites.checkboxdemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class CheckBoxDemo extends Activity
implements CompoundButton.OnCheckedChangeListener {
CheckBox cb;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
cb=(CheckBox)findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
/*
cb.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener(){
public void onCheckedChanged(
CompoundButton buttonView,
boolean isChecked) {
}
}
);
*/
}
public void onCheckedChanged(
CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
cb.setText("This checkbox is: checked");
}
else {
cb.setText("This checkbox is: unchecked");
}
}
}
------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This checkbox is: unchecked" />
------------------------------------
package com.kites.checkboxdemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class CheckBoxDemo extends Activity
implements CompoundButton.OnCheckedChangeListener {
CheckBox cb;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
cb=(CheckBox)findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
/*
cb.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener(){
public void onCheckedChanged(
CompoundButton buttonView,
boolean isChecked) {
}
}
);
*/
}
public void onCheckedChanged(
CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
cb.setText("This checkbox is: checked");
}
else {
cb.setText("This checkbox is: unchecked");
}
}
}
------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This checkbox is: unchecked" />
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>
------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------
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"
/>
-------------------------
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>
--------------------------------
<%@ 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>
------------------------------------------------------------------------------------------------------------------------------------------------
----------------
<%@ 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>
---------------
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());
}
}
--------------------------------------------------------------------------------------------------------------------------------
----------------
<?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>
-------------------------------------------------------------------------------------------------------------------------------------
-------------
<%@ 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");
}
}
-------------------------------------------------------------------------------------------------------------------------
----------------
<?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>
--------------------------------------------------------------------------------------------------------------------------------
--------------
<%@ 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>
------------------------------------------------------------------------------------------------------------------------------
----------------------
<%@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 ....................
----------------------------------------------------------------------------------------------------------------------
----------------
<!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 ....................
----------------------------------------------------------------------------------------------------------------------
Friday, July 27, 2012
Struts2 Programs 006 Stream Result
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" extends="struts-default">
<action name="resultStream">
<result name="success">/jsp/page.jsp</result>
</action>
<action name="download" class="com.kites.StreamResultExample">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;filename="testFile.txt"</param>
<param name="bufferSize">1024</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>
--------------------------------------------------------------------------------------------------------------------------------------
StreamResultExample.java
-------------------------------------------
package com.kites;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class StreamResultExample extends ActionSupport{
private InputStream fileInputStream;
public InputStream getFileInputStream() {
return fileInputStream;
}
public String execute() throws Exception {
fileInputStream = new FileInputStream(new File("downloadfile.txt"));
return SUCCESS;
}
}
----------------------------------------------------------------------------------------------------------------------------------
page.jsp
------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Chain Result Example</title>
</head>
<body>
<font color="megenta" size="6" face="Comic Sans MS">Stream Result example</font><br clear="all"/><br clear="all"/>
<s:url action="download" id="copy"></s:url>
<strong><font color="green" size="5" face="arier">Click on <s:a href="%{copy}">file</s:a> to Download</font></strong>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------
downloadfile.txt
------------------------------
Struts2 is popular and mature web application framework based on the MVC design pattern. Struts2 is not just the next version of Struts 1, but it is a complete rewrite of the Struts architecture.
The WebWork framework started off with Struts framework as the basis and its goal was to offer an enhanced and improved framework built on Struts to make web development easier for the developers.
After some time, the Webwork framework and the Struts community joined hands to create the famous Struts2 framework.
---------------------------------------------------------------------------------------------------------------------------------------
-----------------
<?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" extends="struts-default">
<action name="resultStream">
<result name="success">/jsp/page.jsp</result>
</action>
<action name="download" class="com.kites.StreamResultExample">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;filename="testFile.txt"</param>
<param name="bufferSize">1024</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>
--------------------------------------------------------------------------------------------------------------------------------------
StreamResultExample.java
-------------------------------------------
package com.kites;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class StreamResultExample extends ActionSupport{
private InputStream fileInputStream;
public InputStream getFileInputStream() {
return fileInputStream;
}
public String execute() throws Exception {
fileInputStream = new FileInputStream(new File("downloadfile.txt"));
return SUCCESS;
}
}
----------------------------------------------------------------------------------------------------------------------------------
page.jsp
------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Chain Result Example</title>
</head>
<body>
<font color="megenta" size="6" face="Comic Sans MS">Stream Result example</font><br clear="all"/><br clear="all"/>
<s:url action="download" id="copy"></s:url>
<strong><font color="green" size="5" face="arier">Click on <s:a href="%{copy}">file</s:a> to Download</font></strong>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------
downloadfile.txt
------------------------------
Struts2 is popular and mature web application framework based on the MVC design pattern. Struts2 is not just the next version of Struts 1, but it is a complete rewrite of the Struts architecture.
The WebWork framework started off with Struts framework as the basis and its goal was to offer an enhanced and improved framework built on Struts to make web development easier for the developers.
After some time, the Webwork framework and the Struts community joined hands to create the famous Struts2 framework.
---------------------------------------------------------------------------------------------------------------------------------------
Struts2 Programs 005 Redirect Action Result
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="public" extends="struts-default">
<action name="login">
<result>/jsp/login.jsp</result>
</action>
<action name="doLogin" class="com.kites.Login">
<!-- Redirect to another namespace -->
<result name="success" type="redirectAction">
<param name="actionName">homePage</param>
<param name="namespace">/secure</param>
</result>
<result name="error" type="redirectAction">
<param name="actionName">errorPage</param>
<param name="namespace">/error</param>
</result>
</action>
</package>
<package name="secure" extends="struts-default" namespace="/secure">
<!-- Redirect to an action in the same namespace -->
<action name="homePage">
<result >/home.jsp</result>
</action>
</package>
<package name="error" extends="struts-default" namespace="/error">
<!-- Redirect to an action in the same namespace -->
<action name="errorPage">
<result >/error.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>
---------------------------------------------------------------------------------------------------------------------------------
Login.java
--------------------
package com.kites;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
public String execute() throws Exception {
System.out.println("Login Action Called");
if(getUsername().equalsIgnoreCase("")|| getPassword().equalsIgnoreCase("")){
return ERROR;
}
else if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){
return ERROR;
}else{
return SUCCESS;
}
}
private String username = null;
public String getUsername() {
return username;
}
public void setUsername(String value) {
username = value;
}
private String password = null;
public String getPassword() {
return password;
}
public void setPassword(String value) {
password = value;
}
}
---------------------------------------------------------------------------------------------------------------------
login.jsp
-------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Chain Result Example</title>
</head>
<body>
<s:form action="doLogin" method="POST">
<tr>
<td colspan="2">
Login
</td>
</tr>
<tr>
<td colspan="2">
<s:actionerror />
<s:fielderror />
</td>
</tr>
<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/>
</s:form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------
home.jsp
-----------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body >
<center>
<h1> Home Page</h1>
<font color=green size=15 face=modern> Welcome </font>
</center>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------
error.jsp
-----------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body >
<center>
<h1> Error Page</h1>
</center>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------
-----------------------
<?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="public" extends="struts-default">
<action name="login">
<result>/jsp/login.jsp</result>
</action>
<action name="doLogin" class="com.kites.Login">
<!-- Redirect to another namespace -->
<result name="success" type="redirectAction">
<param name="actionName">homePage</param>
<param name="namespace">/secure</param>
</result>
<result name="error" type="redirectAction">
<param name="actionName">errorPage</param>
<param name="namespace">/error</param>
</result>
</action>
</package>
<package name="secure" extends="struts-default" namespace="/secure">
<!-- Redirect to an action in the same namespace -->
<action name="homePage">
<result >/home.jsp</result>
</action>
</package>
<package name="error" extends="struts-default" namespace="/error">
<!-- Redirect to an action in the same namespace -->
<action name="errorPage">
<result >/error.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>
---------------------------------------------------------------------------------------------------------------------------------
Login.java
--------------------
package com.kites;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
public String execute() throws Exception {
System.out.println("Login Action Called");
if(getUsername().equalsIgnoreCase("")|| getPassword().equalsIgnoreCase("")){
return ERROR;
}
else if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){
return ERROR;
}else{
return SUCCESS;
}
}
private String username = null;
public String getUsername() {
return username;
}
public void setUsername(String value) {
username = value;
}
private String password = null;
public String getPassword() {
return password;
}
public void setPassword(String value) {
password = value;
}
}
---------------------------------------------------------------------------------------------------------------------
login.jsp
-------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Chain Result Example</title>
</head>
<body>
<s:form action="doLogin" method="POST">
<tr>
<td colspan="2">
Login
</td>
</tr>
<tr>
<td colspan="2">
<s:actionerror />
<s:fielderror />
</td>
</tr>
<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/>
</s:form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------
home.jsp
-----------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body >
<center>
<h1> Home Page</h1>
<font color=green size=15 face=modern> Welcome </font>
</center>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------
error.jsp
-----------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body >
<center>
<h1> Error Page</h1>
</center>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------
Subscribe to:
Posts (Atom)