/**
* Servlet implementation class Captcha
* How to create captcha in jsp servlet
*/
public class Captcha extends HttpServlet {
private static final long serialVersionUID = 1325598241;
private int height = 25;
private int width = 138;
public static final String CAPTCHA_KEY = "captcha_key_name";
/**
* @see HttpServlet#HttpServlet()
*/
public Captcha() {
super();
// TODO Auto-generated constructor stub
}
How to copy images from ms word documents 2000, 2003, 2007, 2010 to computer/ How to download resources(images) in a microsoft office document to my system.
Description: The tutorial help you to save images on microsoft word documents(.doc file ) into your system. If you cant right click on image and save to your computer try this.
Open the ms document (.doc file)
Go to file (Or in key board type Alt + F)
in menu there will be an option for saving file, Save As the file in another location.
save As as web page. you can see there in an option for saving the file as webpage in the drop down box
give the extension type to fileName.htm to new file
your file will be now saved as html file , There will separate folder for resources there you can find your images....
Description : Find the missing number in sequence while user try to insert n number randomly into n -1 array. The complexity will be minimum
import java.util.Scanner;
/**
* @author +Jeevanantham R
*
*/
public class MissingNumber {
int inputArray[] = null;
int limit = 0;
private Scanner scanner = null;
private void getInput() {
scanner = new Scanner(System.in);
System.out.println(" Enter total number of elements ");
limit = scanner.nextInt();
int arraySize = limit-1;
System.out.println(" Array size :"+arraySize );
inputArray = new int[arraySize];
for(int i=0; i<arraySize; i++){
inputArray[i]= scanner.nextInt();
}
}
private void findingMissedOne() {
long startTime = System.currentTimeMillis();
int actualValue = (limit * (limit + 1))/2;
int arrayValue = 0;
for(int i : inputArray){
arrayValue = arrayValue + i;
}
System.out.println(" Missing value (from the randomly inserted array) : "+(actualValue - arrayValue));
System.out.println(" Execution time :"+(System.currentTimeMillis()- startTime)+" ms");
}
private void showArray() {
System.out.print(" Array members : ");
for (int i: inputArray) {
System.out.print(i+"\t");
}
}
public static void main(String[] args) {
MissingNumber missingNumber = new MissingNumber();
missingNumber.getInput();
missingNumber.findingMissedOne();
missingNumber.showArray();
}
}
How to find missing number in sequence
My friend had suggested another way to find the missing number in sequence which is much better than the above code. try it and please provide +Akshay Agarwal a feedback
Find missing number in an unordered sequential array
Akshay Agrawal import java.io.*; class MissingNumber { public static void main(String args[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the array size:"); int n=Integer.parseInt(b.readLine());
int a[]=new int[n]; System.out.println("Enter "+(n-1)+" array elements:");
int sum=0; for(int i=0;i { a[i]=Integer.parseInt(b.readLine()); sum=sum+a[i]; }
int s=n*(n+1)/2;
int missing_number=s-sum;
long startTime = System.currentTimeMillis(); System.out.println("missing number in the from randomly inserted sequence="+missing_number); System.out.println(" Execution time :"+(System.currentTimeMillis()- startTime)+" ms");
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService' defined in ServletContext resource [/WEB-INF/landview-mail.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'mailSender' of bean class [com.mapview.landview.service.impl.MailServiceImpl]: Bean property 'mailSender' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
solution : you have forget to create getter and setter method in java class for id specified in xml as bean.
Java networking program to get client ip address in server.
Description : The client tries to establish a connection to server having ip address 127.0.0.1 through port 6363. The socket class is used to establish connection . The server always listen to port 6363 for request from the clients. Once a request reach the server through that port, it establish a connection with that particular client. Multiple clients can connect to server, since i used thread in server.
Description : A program in java to find least common multiple and Highest common factor import java.util.Scanner;
public class LCM {
/** * Computer Science practical question for exams */ private Scanner scanner_ins = null; // To scan user inputed value private int totalNumber = 0; // totalNumber by user private int minimumValue = 0; // Minimum value inside the user inputed array private int lcm = 1; private int hcf = 1; private int [] value_array = null; // User entered value private int [] denominators = {1,9,8,7,6,5,4,3,2}; //private int [] commonMultiples = null; /** * Constructor */ LCM(){ scanner_ins = new Scanner(System.in); } private void getUserInputs() { // TO get user input Total elements System.out.println(" Enter the total number of elements (Say n) : "); totalNumber = scanner_ins.nextInt(); //as like scanf, cin in cpp value_array = new int[totalNumber]; // initialized the size of array for(int i =0 ;i < totalNumber; i++) //This for loop used to get the elements from user { System.out.print(" Enter the "+(i+1)+"th elements : "); value_array[i]=scanner_ins.nextInt(); } } private void findMinimumValue() { // TO Find Minimum value inside value_array[] int temp =0; // A temporary variable temp = value_array[0]; // assingning first value of array to temp for(int i=1; i< totalNumber; i++) // For loop compare the temp values to all other values in the array { if(temp > value_array[i]) { temp = value_array[i]; // changing the temp value to minimum } } minimumValue = temp; }
private void findLCM() { // TO calculate Lcm for(int i=0; i < value_array.length; i++) { lcm = lcm * value_array[i]; } } public static void main(String[] highestCommonfactor) { // main class where program starts LCM lcm_ins = new LCM(); //instance (ins) of Lcm class lcm_ins.getUserInputs(); //for getting user input (total elements, elements into array) long startTime = System.currentTimeMillis(); lcm_ins.findMinimumValue(); //To find minimum value user inputed lcm_ins.findCommomMultiples(); lcm_ins.findLCM(); lcm_ins.showDetails((System.currentTimeMillis() - startTime)); }
private void showDetails(long timeTaken) { System.out.println("\n\t PRIME FACTORS \n ");
System.out.print("\n\t User inputs [ "); for(int i = 0 ; i < totalNumber ; i++) //This for loop used to user inputed values { System.out.print(" " + (value_array[i] * hcf)); } System.out.println(" ]"); System.out.print("\n\t After dividing by common multiples [ "); for(int i = 0 ; i < totalNumber ; i++) //This for loop used to view value array after iteration { System.out.print(" " + value_array[i]); } System.out.println(" ]"); System.out.println("\t H C F is "+hcf); System.out.println("\t L C M is "+lcm); System.out.println("\t Computation Time : "+timeTaken+" ms"); }
}
The above program is just a simple one. Check here to know how to find the missing number in a sequence. the number is inserted randomly. I hope the complexity is minimum b-lazy java
Description : This is a small example to call servlet using ajax jquery. also shows servlet mapping in web.xml file (Deployment descriptor) .How to use external javascript file in java[ajax servlet Tutorial].
Description : The Example show how to call a servlet from jsp using ajax jquery. Data from jsp page will pass to servlet as parameter through ajax call
To receive response from the servlet, Change the code to following
The function sendData() will send data to post method of servlet "JqueryServlet". the data is taken from html tag whose id is " headText ". In the example i have created a text box named headtext in Index.jsp (java server page)
function sendData(){
var mge = $('#headText').val();
Thanking you for reading this post. Hope you will try the code...
Your feedback may help rest of the readers... so please, your valuable comments
Now take a look how cascading style sheet is applied in struts, that is a constant look and feel for all your web pages in your web application . >>> lazy java
Sunday Times 1 Bestseller New York Times 1 Bestseller the global bestseller - Origin is the latest Robert Langdon novel from the author of the Da Vinci Code. 'Fans will not be disappointed' the Times Robert Langdon, Harvard professor of symbology and religious iconology, arrives at the Guggenheim Museum Bilbao to attend the unveiling of an astonishing scientific breakthrough. The evening’s host is billionaire Edmond Kirsch, a futurist whose dazzling high-tech inventions and audacious predictions have made him a controversial figure around the world. But Langdon and several hundred guests are left reeling when the meticulously orchestrated evening is suddenly blown apart. There is a real danger that Kirsch’s precious discovery may be lost in the ensuing chaos. With his life under threat, Langdon is forced into a desperate bid to escape Bilbao, taking with him the museum’s director, Ambra Vidal. Together they flee to Barcelona on a perilous quest to locate a cryptic password that will unlock Kirsch’s secret. To evade a devious enemy who is one step ahead of them at every turn, Langdon and Vidal must navigate the labyrinthine passageways of extreme religion and hidden history. On a trail marked only by enigmatic symbols and elusive modern art, Langdon and Vidal will come face-to-face with a breathtaking truth that has remained buried – until now. ‘Dan Brown is the master of the intellectual cliffhanger’ Wall Street Journal ‘As engaging a hero as you could wish for’ Mail on Sunday ‘For anyone who wants more brain-food than thrillers normally provide’ Sunday Times
/**
* @author deep
*
* program compares todays date with that in db
*
*/
public class JavaDate {
/**
* @param args
*/
public static void main(String[] args) {
String dateInDB = "2011-1-12";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String currentDate = format.format(new Date());
System.out.println(" Current date : " +currentDate);
System.out.println(" date in db : " +dateInDB);
if(currentDate.compareTo(dateInDB) <= 0)
System.out.println("current date is greater ");
else
System.out.println("db date is greater ");
}
Introducing AJAX : asynchronous java and xml for Java web application , Here is a simple example
The below example shows you how java servlet response/replies to ajax request/call from a jsp page. The java server page need not be reload again, only the div refresh. Please try the source code. Deployement Descriptor : web.xml
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Nexegen Technologies</title>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="ajaxDiv">
</div>
<div id = "mydiv">
<input type="button" onclick="verifyPassword()">
</div>
</body>
</html>
XXX XXX XXX XXX XXX XXX XXX XXX XXX
Ajax.js
/*
* creates a new XMLHttpRequest object which is the backbone of AJAX,
* or returns false if the browser doesn't support it
*/
function getXMLHttpRequest() {
var xmlHttpReq = false;
// to create XMLHttpRequest object in non-Microsoft browsers
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
// to create XMLHttpRequest object in later versions
// of Internet Explorer
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (exp1) {
try {
// to create XMLHttpRequest object in older versions
// of Internet Explorer
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (exp2) {
xmlHttpReq = false;
}
}
}
return xmlHttpReq;
}
/*
* AJAX call starts with this function
*/
function verifyPassword() {
var xmlHttpRequest = getXMLHttpRequest();
xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest);
xmlHttpRequest.open("POST", "ForAjax", true);
xmlHttpRequest.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlHttpRequest.send(null);
}
/*
* Returns a function that waits for the state change in XMLHttpRequest
*/
function getReadyStateHandler(xmlHttpRequest) {
// an anonymous function returned
// it listens to the XMLHttpRequest instance
return function() {
if (xmlHttpRequest.readyState == 4) {
if (xmlHttpRequest.status == 200) {
document.getElementById("ajaxDiv").innerHTML = xmlHttpRequest.responseText;
} else {
alert("HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText);
}
}
};
}