May 19, 2008 at 9:10 PM
Hi
<!DOCTYPE HTML PUBLIC ?-//W3C//DTD HTML 4.01 Transitional//EN?>
<html>
<head>
<title>AJAX and Servlet</title>
<script language=?javascript?>
var xmlHttp;
function checkUserExist() {
var username = document.getElementById(?username?).value;
var url = ?/Ajax/AJAXCheckUserServlet?username=? + username;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject){
xmlHttp = new ActiveXObject(?Microsoft.XMLHTTP?);
}
xmlHttp.open(?Get?,url,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback() {
if( xmlHttp.readyState==4 ){
if( xmlHttp.status==200 ) {
document.getElementById(?text?).innerHTML = ?<br/><b>?+xmlHttp.responseText+?</
b>?;
}
}
}
function focusIn(){
document.getElementById(?username?).focus( );
}
</script>
</head>
<body onload=?focusIn();?>
<form>
User Name <input type=?text? id=?username? name=?username? />
<input type=?button? value=?Check User Name Availability? onClick=?checkUserExist()?/>
<div id=? text? ></div>
</form>
</body>
</html>
---------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.*;
public class AJAXCheckUserServlet extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws
ServletException, IOException {
String username = request.getParameter(?username?);
boolean isExist = check(username);
response.setContentType(?text/html?);
response.setHeader(?Cache-Control?, ?no-cache?);
if(isExist){
response.getWriter().write(?User Name exists. Please select other name.?);
}
else{
response.getWriter().write(?Congratulations....User Name is available.?);
}
}
public boolean check(String username) {
Connection con = null;
String url = ?jdbc:
mysql://192.168.10.59:3306/?;
String db = ?javajazzup?;
String driver = ?com.mysql.jdbc.Driver?;
String user = ?root?;
String pass = ?root?;
boolean isExist= false;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery(?SELECT user_name FROM users?);
while (res.next()) {
String un = res.getString(?user_name?);
if(username.equals(un)){
con.close();
isExist = true;
break;
}
}
con.close();
}
catch (SQLException s){
System.out.println(?SQL code does not execute.?);
}
}
catch (Exception e){
e.printStackTrace();
}
return isExist;
}
}
---------------------------------
Related Tutorials/Questions & Answers:
Name Display in alert box - JSP-ServletName Display in
alert box Dear Sir,
Please any one help me......... when i enter some value in text that value is already in database
display the
alert box but the value is not in data base
alert box is not
display Display two alert box alternately by clicking on text Display two
alert box alternately by clicking on text
In this tutorial , we will discuss about how to
display two
alert box
alternately by clicking on text... on it ,it will show a
alert box. But when we click on it again ,
it shows second
alert box Advertisements
Display alert box on clicking linkDisplay alert box on clicking link
In this tutorial, we will
display alert box... to
display alert box in jQuery on link click?”:
Mylink.html
<... in the block.
The code given below is used to
display alert box on clicking link
JavaScript display variable in alert in
alert box? I am using javascript.
<html>
<head>
<script...";
var city = "Delhi";
alert(
name +" is in "+ city);
}
</script>
<... put variable or any statement
in
alert which you want to
display Java Alert Box JOptionPane class to
display the message
alert box. JOptionPane class is available...Java
Alert Box
In this example we will describe java
alert box. First of all we have created
class than main method after that we have created
alert box Alert Box in FlexFlex
Alert Box Components
Adobe Flex provides many types of components, in this tutorial we will study visual component.
1.
Alert Box: In the present tutorial we will see how to
display simple text using
Alert Box. An
Alert Box alert box in iphonealert box in iphone hello,
how can i show
alert box in my iphone application??
hello,ADS_TO_REPLACE_1
you can use this code for show the
alert ..
UIAlertView *alt = [[UIAlertView alloc] initWithTitle: @"Title
display the employee namedisplay the employee name when i will select one employee designation based on that employee designation
display the particular designation employee
name display in another select
box how it possible using servlet and mysql
why alert box is not appearing in servlets...?why
alert box is not appearing in servlets...? //example.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class adduser extends HttpServlet
{
public void init(ServletConfig config
Flex Alert Box example Flex
Alert Box example
Alert box is a dialog
box that appears on window with some...
Alert &
box,
Alert is a
class defined inside the mx.controls package
To display suggestions in a text box - Ajax:'A'), the names that starts from 'A' have to
display in the text
box... to
display( These values should get from exisiting database).
Name: A( When i...To
display suggestions in a text box Hi All,
I have a requirement
how to get selected name from combo box of worker
name within d combo
box and
display that id into a text
box.
plz...how to get selected
name from combo
box i have fetched all records of worker i.e worker
name. on a test.jsp
and dispayed it into combo
box ...my
how to get selected name from combo box of worker
name within d combo
box and
display that id into a text
box.
plz...how to get selected
name from combo
box i have fetched all records of worker i.e worker
name. on a test.jsp
and dispayed it into combo
box ...my
how to get selected name from combo box of worker
name within d combo
box and
display that id into a text
box.
plz answer...how to get selected
name from combo box i have fetched all records of worker i.e worker
name. on a test.jsp
and dispayed it into combo
box ...my
how to get selected name from combo box of worker
name within d combo
box and
display that id into a text
box.
plz answer...how to get selected
name from combo box i have fetched all records of worker i.e worker
name. on a test.jsp
and dispayed it into combo
box ...my
how to get selected name from combo box of worker
name within d combo
box and
display that id into a text
box.
plz answer...how to get selected
name from combo box i have fetched all records of worker i.e worker
name. on a test.jsp
and dispayed it into combo
box ...my
Automatically display in text box - JSP-ServletAutomatically
display in text box Dear Deepak Sir,
When i enter some text in text box.That corresponding value in database,the value
display in another text
box using ajax.
Thanks & Regards,
VijayaBabu.M
Code to store SubCombo box Name - Development processCode to store SubCombo
box Name Hi, In the following code i want to store Sub-combo
box(Second combo in Department field)
name instead of value. plz send me code tfor that
Add Data
var arr = new Array();
arr["Select
depending on the form name i have to display the messagedepending on the form
name i have to
display the message depending on the form
name i have to
display the message.
for example, i have 3 jsp pages... on contact us after entering all details page has to
display message like"thank u
how to display the value of termcell name in labelhow to
display the value of termcell
name in label want to
display the tercell
name in label report of pending apllication of termcellname code...="
display"%>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
<
how to display webservice response in a text boxhow to
display webservice response in a text box Hallo,
i have created a webservice and when i sended request to my webservice its sending proper response . the point is how to dispaly the response values in a text
box usinj
display from select box - JSP-Servletdisplay from select box I am doing a jsp project. In this jsp project i have to show the photos in one cell depending on the selection from other selection
box which is in the same page.
The photos are stored
jQuery alert() about how an
alert box can
display information. This example displays an
alert box...jQuery
alert()
In this jQuery tutorial we will discuss how an
alert box works in jQuery. Moreover, this tutorial will discuss in details about
alert box alertalert after pressing ok button in
alert message it has to stop...;
if(username==""){
alert("Enter Username!");
return false;
}
if(password==""){
alert("Enter Password!");
return false;
}
return true;
}
</script>
<
JavaScript Checkbox In DropDown box. An
alert box will
display the
selected values.
Here is the code...JavaScript Checkbox In DropDown
box
In this section, you will learn how to
display the checkboxes inside the
dropdown
box. Now to implement this, we have
Display current date in text box in JSP using javascriptDisplay current date in text
box in JSP using javascript
In this section you will learn how to
display current date in text
box using JavaScript.For this purpose, we have used JavaScript Date object. The getDate() method returns the day
Display a dialog box with Java Error the execution
of a program using javaw ,the program code
display a dialog
box name Java...
Display a dialog
box with Java Error
... you a code that help you in
implementation of dialog
box with Java Error
JSP Alert:
If you will not enter the Login
Name, an
alert box displays showing error... to create
alert box in a JSP
page. Before applying validation we create a JSP file... == ""){
alert ( "Please enter Login
Name." );
document.loginform.userName.focus
alert in jsp alert message?, please give me a code how to write
alert box in jsp...
alert in jsp if(pass.equals(pwd))
{
Statement st1...");
%>
alert("password is successfully changed");
<
alert for validationalert for validation i want to put
alert on the text
box that enter...)
if (cpos1==-1 || cpos2==-1){
alert("The date format must be : dd/mm/yyyy... || pmonth<1 || pmonth>12){
alert("Enter a valid month")
return
NameName make a program that take a input from user in alphabet and show all the
name of that character
E.g User give character "B".
The program shows all the human names which starts from B.
Java show all names
jQuery alert() an
alert box can
display information. In this example we will
display an
alert box...jQuery
alert()
In this section we will discuss about
alert box in jQuery...
information at runtime.
Alert box can be popped up after happening an event
Java Message Box will
display a message with message as "This is a Message
Box.".ADS...,
customizing the component the dialog
display and specify where message
box.../No.
showInputDialog : This will
display a message
box that
accept input from