Need a jsp code

Need a jsp code

I need a jsp code in which when i select a value from dropdowm list,(for eg say id) then all the remaining details(eg:name,age,address) about that id must be displayed in the corresponding textboxes from the database at the moment the dropdown value is selected without the use of button..please help me for this.

View Answers

June 25, 2012 at 12:06 PM

The given code retrieves the employee name in the dropdown. When the user selects any name from the dropdown, related data will get displayed on the textboxes. Here we have used Ajax.

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 Name");
}
}
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 Name");
  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 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='"+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();
}
%>

June 25, 2012 at 12:07 PM

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     
          )









Related Tutorials/Questions & Answers:
need JSP Code.
need JSP Code.  **Hi I need JSP code for selling Products which are in Database. Please can any one help for this.URGENT... Thank You..! Abhijeet
Need a JSP CODE
Need a JSP CODE  *Hi I need JSP source code for selling products which are in database.. please can any one help me ..URGENT* Thank You
Advertisements
Need a jsp code
Need a jsp code  I need a jsp code in which when i select a value.....please help me for this.   The given code retrieves the employee name...)For the above code, we have created following table: CREATE TABLE `employee
i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum... of generate ids each should have some range...plz give the source code in jsp with ms
need complete jsp code for transactions using mysql - WebSevices
need complete jsp code for transactions using mysql  iam doing online banking project.i want the code to transfer funds from one account to another... to lasya or lasya to prathika. I need complete jsp code for transactions using
need of code
need of code  howto convert greyscale image to binary image in java
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional... is the required code: import java.util.*; class Vehicle { int
urgent need for jsp code with mysql query for uploading and downloading file - JSP-Servlet
urgent need for jsp code with mysql query for uploading and downloading file  can anyone tell me how to upload and download a doc file using jsp with mysql as the back end... and kindly help me to create the table too
I need jsp code for how to write text field value into property file.
I need jsp code for how to write text field value into property file.  Hi , I need to set the text field value into property file using jsp code. Example : Username : Valar , I have entered the value "Valar" in the text field
need a jsp example - JSP-Servlet
need a jsp example  I need a jsp example to send a voice message or a audio .wav file from my pc to a mobile phone
Need sample code
Need sample code  Need code for graph which shows the performance comparission of aprior algorithm and coherent rule algorithm.plz can any one help me i need in a week
jsp code
jsp code  what are the jsp code for view page in online journal
need code for file browser
need code for file browser  hi, i need to write a code to browse the file in my computer using Jsp or java.. what is the code for file browser?   JSP Code for browsing: 1)page.jsp: <%@ page language="java" %>
Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual
Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual
Need an example of basic code.
Need an example of basic code.   Im working on an art project that I want to use some code in, and I am proficient in python but that looks fairly simple so I was hoping java would look more impressive. So I just need a visual
jsp code - JSP-Servlet
jsp code  I need code for bar charts using jsp. I searched some code but they are contain some of their own packages. Please give me asimple code... friend, Code to solve the problem : Thanks
need code - Java Beginners
need code   i want to take the html coding. if user give a input html file the out is html coding in text file. i want to take html coding only... are sending you a sample code which will be helpful to you. import java.io.
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 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
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have... using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen(need to know how I can adjust it based on the cureen system's screen resolution
code need - Java Beginners
code need  hi i want to code doing for this. If i have enter the text file in my java project. example input is 1,2,3,4,5(it is in input text file...)  Hi Friend, Try the following code. We hope this will help you
jsp code
jsp code  i want health management system project code using jsp.its urgent
JSP code for forget password
JSP code for forget password  I need forget password JSP code.. example http://www.roseindia.net/users/forgotpassword.html
Need Java Source Code - JDBC
Need Java Source Code  I have a textfield for EmployeeId in which... be implemented.  Hi friend, Please send me code because your posted.... http://www.roseindia.net/jsp/ Thanks
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
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 code  I get an error when i execute the following code : <... = con.createStatement(); st.executeQuery(query); %> <jsp:forward page="address.jsp"></jsp:forward> HTTP Status 500 - type Exception report message
jsp code - JSP-Servlet
jsp code  Can anyone help me in writing jsp/servlet code to retrieve files and display in the browser from a given directory.  Hi Friend, Try the following code: Thanks
jsp code
jsp code  how to display date in drop down list by jsp thus the date start from current date and for next year it has to check leap year function to february then it display 30 for some months else 31 for other months
jsp code - JSP-Servlet
jsp code  sample code for change password example Old Password: new Password: confirm Password
source code in jsp
source code in jsp  i need the source code for online payment in jsp
Need source code - Swing AWT
Need source code  Hai, I need a source code for developing the project, title is "Face Recognition" and the backend as My-sql.... Thanks & Regards
jsp code - JSP-Servlet
jsp code  sample code to create hyperlink within hyperlink example: reservation: train: A/C department non A/c Department
jsp code - JSP-Servlet
jsp code  how to count no of clicks made on a link and save it on database( using jsp)  Hi Friend, Try the following code: 1)click.jsp var numberOfClicks = 0; function hello(){ numberOfClicks
jsp code - JSP-Servlet
jsp code  in a jsp a table is existed ,in table each row contain one checkbox and name and desription how to delete specific rows in a table .  Hi Friend, Try the following code: 1)form.jsp: Name
need code for login in asp.net with c#
need code for login in asp.net with c#  hai iam trying to develop a project in asp.net with c#,so i need a code for login page using which admin and other users can log in.plz help me, thanks in advance
JSP code - JSP-Servlet
me how to link these pages with each other using JSP..and how to write the code using JSP.. requriment for Newuser: 1>fname,lastname 2>Loginname...JSP code  hello,i working in project with JSP technology,i have one
need java code - Java Beginners
need java code  I want java code for connect to bit.ly and our link is converted into shorten link and give me response. as a converted link
NEED CODE FOR APPLICATION - Development process
NEED CODE FOR APPLICATION  i want to build a supermarket software that has the features of stock taking and receipt priting. can u help me
Need source code - Swing AWT
Need source code  Hai, I need a idea and code for developing the project "Face Recognition" with the backend as My-sql.... Thanks & Regards
Need the Following MobileApplication Related Code
Need the Following MobileApplication Related Code  Hi, I need java...: and one Daemon Thread class need's to run while doing the above operations and if you can provide code in switch cases,I feel more happy. Please reply me ASAP.ADS
jsp code - JSP-Servlet
jsp code  in my table there are 3 fields named orderid ,itemname, itemqty. i want code that fetch orderid in dropdown... on select dropdown get table of item details of that orderid... there are multiple items at one orderid
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
need a Sample code - Development process
need a Sample code  i want run the python script in java code by using Runtime class and output should be formed like XML format.please help me. Advanced Thanks, Krishna
need someone to do/help with code
need someone to do/help with code  i need someone to do a code for me. It is a restaurant menu that displays a list of 10 food items. A customer..., along with the number of items sold..please help did a code 500 times cant
code in jsp
code in jsp  hi.. I had started a project on college admission system in which two operators has been introduced one is admin who can view all... want a code to sort a list of students on the basis of there 12% marks and AIEEE
jsp code - JSP-Servlet
jsp code  how to write a code in jsp with out using servelts finding sum and avg of 40 numbers  Hi Friend, Try the following code: Thanks  Hi Friend, Do one change in the provided code.As we

Ads