Importing a Java Method in to JSP Page

package com.mugil.servlet;

public class Sample1 
{
  static int pincode = 600018;
  
  public String toString()
  {	
    return "600018";
  }
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "com.mugil.servlet.Sample1"%>    
 <body>
   <%=new Sample1()%>
 </body>

Note:
The following Code wont work

  <%=new Sample1();%>
  <% =new Sample1()%>

To remove the Linkedin contacts from the Mobile phone follow the steps as below

Go to phone > Settings > applications > Manage applications > ALL > LinkedIn > Clear Data

Now you need to restart the Android once you are done with this

We are Done

Below are the code sample which shows how to carry out basic tasks in Jython.The Files should be shared as .py extension if your are using eclipse.To know abount configuring jython in eclipse follow the
Link

Printing a Message in Console

  print 1 + 1
  print "Hello" + " World "
  print "Hello Jython "
  print "Jython ", "Scripting"

Simple Jython Function that Takes Argument and Print Values

def displayName(x):
 print x 
 
displayName("Mugil")

Jython Function which Calculates the Factorial of a Number

def factorial(x):
 if x<=1 : 
  return 1    
 return x * factorial(x-1)
 
print factorial(3)

Function which compares Two Strings in If Condition

def compareName(FirstName, LastName):
 if FirstName == LastName:
  print "They are Equal"
 else:
  print "They are Not Equal"  
   
   
compareName("Jython", "Jython")

Conditional Operators
Function which Perform AND, OR and Not Ops

def BoolOps(pOne, pTwo): 
 if pOne and pTwo:
  print "They are Equal"
 else:
  print "They are Not Equal" 
  
BoolOps(1,0)

Jython Conditional Operators

Jython Supports Three Numeric Values as Below

  • Integers
  • Long
  • Floating Point

Array from Delimited String and Looping through It

Names = "A, B, C, D, E"

arrNames = Names.split(",")

for x in range(len(arrNames)):
 print arrNames[x]

Array Function

Names = "A,B,C,D,E,F,G,H,I,J,K,L,M"

arrNames = Names.split(",")

#B
print arrNames[1]

#['B']
print arrNames[1:2]

#['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']
print arrNames[1:]

#['A', 'B', 'C', 'D', 'E', 'F']
print arrNames[:6]

#['B', 'C', 'D', 'E']
print arrNames[1:5]

#['H', 'I', 'J']
print arrNames[-6:-3]

#['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']
print arrNames[:]

#['A', 'C', 'E', 'G', 'I', 'K', 'M']
print arrNames[::2]

Concatenating Two Arrays together

Names1 = "A,B,C"
Names2 = "D, E, F"

arrNames1 = Names1.split(",")
arrNames2 = Names2.split(",")

arrNames = arrNames1 + arrNames2

for i in range(len(arrNames)):
 print arrNames[i]

import jarray
import java
myArray = jarray.array(["mugil", "Vannan"], java.lang.Object)

rc.logMessage(str(len(myArray)))

for value in myArray:
 rc.logMessage(value)

For Character

myArray = jarray.array(["m", "V"], "c")

For Integer

import jarray
import java
myArray = jarray.array([1,2,3,4,5,6], java.lang.Integer)

rc.logMessage(str(len(myArray)))

for value in myArray:
 rc.logMessage(str(value))

I am having single column in excel sheet which I want to replicate in Jython scripting and place it in adjacent column.The Content of the Column is as in the Pic below

from jxl import *
from jxl.write import *
from java.io import File
workbook = Workbook.getWorkbook(File("$(TargetFolder)\Book2.xls"))
targetWorkbook = Workbook.createWorkbook(File("$(TargetFolder)\Book2.xls"),
workbook)
sheet = targetWorkbook.getSheet(0)
columnIndex = 0

rowCount = sheet.getRows()

for i in range(rowCount):
 row = sheet.getRow(i)
 content = row[columnIndex].getContents()
 rc.logMessage("Content -> " + content)    
 wc = sheet.getWritableCell(1,i)
 newLabel = Label(1,i, content)
 sheet.addCell(newLabel)
 
targetWorkbook.write() 
targetWorkbook.close()
workbook.close()

Before running Script
null

After running Script
null

How to get Total Columns Returned by Query

 ResultSet rs = stmt.executeQuery(strSQL);
 ResultSetMetaData rsmd = rs.getMetaData();
 int columnsNumber = rsmd.getColumnCount();

How to get Column Name from Query

 ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
 ResultSetMetaData rsmd = rs.getMetaData();
 String name = rsmd.getColumnName(1);

How to get Column Count from Query and Loop Through That

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();

// The column count starts from 1
for (int i = 1; i < columnCount + 1; i++ ) {
  String name = rsmd.getColumnName(i);
  // Do stuff with name
}

To Find a Column with particular Name

 ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
 rs.getString(rs.findColumn("fullname"));

How to get List of Column Names from Query and Store it in a Array

 ResultSetMetaData meta = resultset.getMetaData();  
 Integer columncount = meta.getColumnCount();
 int count = 1 ; 
 String[] columnNames = null;

 while(columncount <=count)
  columnNames [i] = meta.getColumnName(i);

 System.out.println (columnNames.size());