ajax code in pure jsp page

ajax code in pure jsp page

how can we write ajax code in pure jsp page?

View Answers

March 21, 2012 at 3:35 PM

1)selectname.jsp:

<html>
<head>
<script type="text/javascript">
function showEmp(emp_value){ 
 if(document.getElementById("address").value!="-1"){
 xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
 alert ("Browser does not support HTTP Request")
 return
 }
var url="getvalue.jsp"
url=url+"?name="+emp_value
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
else{
 alert("Please Select Employee Id");
}
}
function stateChanged(){ 
document.getElementById("email").value ="";
document.getElementById("address").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
if(strar.length==1){
  document.getElementById("address").focus();
  alert("Please Select Employee Id");
  document.getElementById("email").value =" ";
document.getElementById("address").value =" ";
 }
 else if(strar.length>1) {
var strname = strar[1];
document.getElementById("address").value= strar[1];
document.getElementById("email").value= strar[2];
 }
 } 
}

function GetXmlHttpObject(){
var xmlHttp=null;
try{
 xmlHttp=new XMLHttpRequest();
 }
catch (e) {
 try {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
</script>
</head>
<body>
<form name="employee">
<br><br>
<table border="0" width="400px" align="center" bgcolor="#CDFFFF">
<div id="mydiv"></div>
   <tr><td><b>Select Employee Name</b></td><td> 
   <select name="name" onchange="showEmp(this.value);">
   <option value="-1">Select</option> 
<option value="Angelina">Angelina</option>
<option value="Martina">Martina</option>
<option value="Julia">Julia</option>
<option value="Angel">Angel</option>
 </select>
</td></tr>
<tr><td ><b>Employee Address:</b></td><td>
<input  type="text" name="address" id="address" value=""></td></tr>
<tr><td><b>Employee Email:</b></td><td>
<input  type="text" name="email" id="email" value=""></td></tr>

</table>
</form>    
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>

2)getvalue.jsp:

<%@page import="java.sql.*"%>
<%
String emp_name = request.getParameter("name").toString();
String data="";
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root"; 
String password = "root";

int sumcount=0; 
Statement st;
try {
Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select * from employee where name='"+emp_name+"'";

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
data = ":" + rs.getString("address") +":"+  rs.getString("email");
}
out.println(data);
}
catch (Exception e) {
e.printStackTrace();
}
%>

March 21, 2012 at 3:36 PM

continue..

3)For the above code, we have created following table:

CREATE TABLE `employee` (               
            `id` bigint(255) default NULL,        
            `name` varchar(255) default NULL,     
            `address` varchar(255) default NULL,  
            `contactNo` int(255) default NULL,    
            `email` varchar(255) default NULL     
          )

For more information, visit the following link:

http://www.roseindia.net/jsp/comboSelect.shtml









Related Tutorials/Questions & Answers:
ajax code with jsp - Ajax
ajax code with jsp  hi , Sorry for insufficient data.i m making some correction on question. I have to perform some calculation on my jsp page. i want to do it automatically (using ajax in jsp). problem is - i hv two
ajax and jsp code - Ajax
ajax and jsp code  can u please give me the code for retriving the data from database using ajax our requriment is if i select country name in listbox display the corresponding all the states. using jsp and ajax   
Advertisements
Ajac code with jsp - Ajax
Ajac code with jsp  hi , i am beginner for ajax.I have to perform some calculation on my jsp page. i want to do it automatically that is possible using ajax. problem is - i hv two text box. 1st take
code for jsp - Ajax
code for jsp  please give code for using jsp page and Ajax.Retrive... country.By using jsp and Ajax.    Hello Friend I send the code you...; Hi friend sorry the jsp page for another program look this file
ajax code for jsp
ajax code for jsp  How to write ajax code to retrieve information on to particular part of webpage when we select option from drop down box
refresh jsp page - Ajax
refresh jsp page  Code for refresh a web page in jsp.  Hi friend, function refreshpage() { window.location.reload
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly   index.html <... request; // The variable that makes Ajax possible! try{ // Opera 8.0
embedding a chatting code in jsp page - JSP-Servlet
embedding a chatting code in jsp page  i need to know that how can i embed my chatting code in java networking in my jsp page
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  ... sales report data from oracle database to jsp page please any one know how to do this send me a code to my email:[email protected] its a humble request my team
jsp - Ajax
jsp  I'm very new in using the jsp and ajax, i have some JSP pages and i need to add some ajax features in my jsp page, for the example i need.... How can I implement this and then add this to my jsp page? please
using jsp's....and ajax - Ajax
using jsp's....and ajax  Hi, i need code using ajax .....in a text box when i enter an alphabet i should get list of words starts with the alphabet given in the text box
ajax code - Ajax
ajax code  hello sir, how can i insert a text field dynamically by using ajax   Hi Friend, Try the following code: 1)ajax.jsp...= document.getElementById("name").value; window.open("http://localhost:8080/examples/jsp
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and ajax
jsp & ajax
jsp & ajax  how to enable or disable textbox using radio buttons by using jsp and ajax? plz help me.... i m new in jsp & ajax
Ajax code
Ajax code   I want an ajax code in jsp where selecting a listbox... be from database..Please help me....   1)country.jsp: <%@page import...: (adsbygoogle = window.adsbygoogle || []).push({}); <%@page import="java.sql.
code problem:ajax - Ajax
code problem:ajax  Hi,I am using ajax to populate a select box.for this I am writing out.write("ONE"); like that.it runs fine in firefox.bt not in IE.Can anyone help me out this... thanks
How to use ajax in jsp?
How to use ajax in jsp?  Hi, How i can access the server-side data in JSP using the Ajax? Thanks   Hi, You can use the Ajax code to access the server side data from JSP page. Check the tutorial Combo Box Using Ajax
Ajax with jsp - Ajax
Ajax with jsp  multiple combo boxes with ajax in jsp?  Hi friend, I am sending you a link. I hope that, this link will help you. Please visit for more information. http://www.roseindia.net/jsp
ajax jsp - Ajax
ajax jsp  multiple combo with ajax using jsp?  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/comboSelect.shtml Thanks
JSP and AJAX very urgent - Ajax
JSP and AJAX very urgent  Hi Team, This is Ragavendran.R.. I..., there will be tag involved in JSP page. But in my current project, I am using too many tags in my JSP page and as a result, I am getting only the last div tag updated
ajax code
ajax code  Explain me this code function disp_branch(val) { if(unit_branch!=val){ unit_branch=val; xmlHttp=GetXmlHttpObject... not support HTTP Request") return } var url="index.php?q=<
Jsp Code:Refreshing Page - Java Beginners
Jsp Code:Refreshing Page  Dear Frnds, I have a problem where i need to refresh a page based on the button click. once a page is updated, it should refresh the data in another page. structure is given bellow... Empid EmpName
using ajax and jsp (struts) to login and remain on same page.
using ajax and jsp (struts) to login and remain on same page.  I am a fresher... I can forward my login page to success page using struts, but I want to remain on same login page and just want to display loggers name ... I don't
ajax code - Ajax
ajax code  hi can any body tell me how i can create an autocomplete textbox in java using ajax. For example in google when we type any thing it will reflect the matching details according the character.. Hope some body
problem with code - Ajax
to use ajax i wrote the code of jsp and the remaning code by using ajax is not wrritened by observing these below code please try the remainning ajax code its...problem with code  hi friends i am sending a code in that when we
Jsp and ajax
code. Plz anybody help me.Its urgent. al.jsp <%@ page import="java.sql.*" %> <%@ page import="javax.swing.*" %> <%! Connection c...Jsp and ajax  Hi I am using jsp and ajax.I am retrieving
Jsp and ajax
code. Plz anybody help me.Its urgent. al.jsp <%@ page import="java.sql.*" %> <%@ page import="javax.swing.*" %> <%! Connection c...Jsp and ajax  Hi I am using jsp and ajax.I am retrieving
Jsp and ajax
code. Plz anybody help me.Its urgent. al.jsp <%@ page import="java.sql.*" %> <%@ page import="javax.swing.*" %> <%! Connection c...Jsp and ajax  Hi I am using jsp and ajax.I am retrieving
Jsp and ajax
code. Plz anybody help me.Its urgent. al.jsp <%@ page import="java.sql.*" %> <%@ page import="javax.swing.*" %> <%! Connection c...Jsp and ajax  Hi I am using jsp and ajax.I am retrieving
jsp and ajax - JSP-Servlet
jsp and ajax  i had some problem i want to display the current system date and time in each and every page of my project just i want the time to be automatically updated for every second for that i want to make an ajax call
code for user registration page and login page of emails using jsp
code for user registration page and login page of emails using jsp  hiiiiiii please send me the code for user registration page and login page of email using jsp and servlets and also code for database connectivity to oracle
JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am... from the letter entered in the text box, is present, without reloading the page (Using AJAX. for ur reference, I have included the coding below: Login.html
Values from servlet into dropdownlist in jsp page using ajax
servlet into dropdownlist of jsp page...kindly check the code attached and tell me...Values from servlet into dropdownlist in jsp page using ajax  1) jsp file <%@page import="java.sql.Statement"%> <%@page import
jsp code
jsp code  what are the jsp code for view page in online journal
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. my code: login.jsp <html> <head> <meta http-equiv
Sample Ajax Code
Sample Ajax Code  Sample Ajax Code for getting values from another JSP   The below code is helpful to access another Action class...//==========JSP File================ <%@ page contentType="text/xml" %> <USERS>
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. login.jsp: print("<html> <head> <meta http-equiv="Content-Type" content="text
ajax in java - JSP-Servlet
ajax in java  The below code is for a php page but I want this in JSP page. function postRequest(strURL){ var xmlHttp... page and remember some points : 1. replace the code var url = "login.php
Ajax Code Libraries and Tools
Ajax Code Libraries and Tools        Code libraries and loots for the development of your Ajax... only with help of AJAX. This page, however, is not about AJAX (or any other
JSP CODE
JSP CODE  what is the code for downloading images from database using JSP?   Please visit the following link: http://www.roseindia.net/jsp/downloadimage.shtml
jsp+ajax validation
jsp+ajax validation  hi, I have created the jsp form (course... 60% in the drop down list .how to validate student from using ajax and jsp... have created student jsp form where it should display register number
jsp code
jsp code  hi i am Ruchi can anybody plz tell me the jsp code... visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml www.roseindia.net/jsp/searchbook.shtml
online shopping cart complete coding in pure jsp
online shopping cart complete coding in pure jsp  online shopping cart complete coding in pure jsp   Please visit the following link: JSP Online shopping cart
jsp code
jsp code  i want health management system project code using jsp.its urgent
JSP Code - JSP-Servlet
JSP Code  Create a html reader JSP tag that read the html page from a link and will display the contents on the JSP. Do not use include directive
JSP CODE
JSP CODE  Please help me as soon as possible.Its Urgent. I am working on my college ALUMNI PORTAL. I want to have a ADD FRIEND option in a user's profile. Please send me code
Ajax using jsp
Ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import...); } %> Is there Any error...........In first Page I use ajax for displaying
jsp code
jsp code  i want to jsp code which are working as,i have three drop down menu 1st menu for class second menu for subject and third menu as chapter... according to selectde menu,,,,please send me such type code,,,,plz help me
JSP code - JSP-Servlet
JSP code  hello,i working in project with JSP technology,i have one page Login.html and on there two options NewUser and Recoverpassword..can u tell me how to link these pages with each other using JSP..and how to write the code
Ajax validation - JSP-Servlet
Ajax validation  How to fade out the images when an onblur function is called moving from a text box to another?? can anyone help out with with the code

Ads