Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Interview-Questions need help...................please
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


logeswaran
need help...................please
4 Answer(s)      2 years and 5 months ago
Posted in : JSP-Interview Questions


I have a problem in my JSP Coding. How to retrive value from database in to text field when user select one value from dropdown list. For example, if user select on of name in dropdown list (the name list is also coming from database)every information about the person should show in texfield that already create in the web page. I'm really stuck on this area. Please help me.

By the way, I'm using access Database and JSP coding.

Thank You.


Advertisement
View Answers

July 9, 2012 at 12:57 PM


Here is an application that retrieves table name from database and display in dropdown box. When the user select particular name from dropdown corresponding values will get displayed into textboxes.

1)selectname.jsp:

<%@page import="java.sql.*"%>
<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> 
   <%
   Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","root");
String query = "select * from employee";

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
%>
<option value="<%=rs.getString("name")%>"><%=rs.getString("name")%></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_id = request.getParameter("name").toString();
String data="";

int sumcount=0; 
Statement st;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","root");
String query = "select * from employee where name='"+emp_id+"'";

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();
}
%>


July 9, 2012 at 12:58 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
)



July 9, 2012 at 12:59 PM


Please visit the following link:

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



July 9, 2012 at 5:31 PM


thank you very much



Related Tutorials/Questions & Answers:
need help please
need help please  Dear sir, my name is logeswaran. I have a big problem that I can't find the solution for a program. How can I block a user from enter a page second time. Please help me. By the way I'm using Access database
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer n is written n! (pronounced ‚?? n factorial‚??) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1
Advertisements
need help...................please
need help...................please  I have a problem in my JSP Coding... on this area. Please help me. By the way, I'm using access Database and JSP coding...("GET",url,true) xmlHttp.send(null) } else{ alert("Please Select Employee Id
help please?
help please?  Define a class named Circle with the following properties: ‚?Ę An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
help please?
help please?  Define a class named Circle with the following properties: List item ‚?Ę An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: ? An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
Confusion on Functions. Help Please?!
Confusion on Functions. Help Please?!  Write a program which has a number of functions for getting the area i.e. area of circle, area of square, area... not getting anywhere with it really :( Some help please
Java Variables Help Please!
Java Variables Help Please!  Hi, I just started with java and i need help with my school project, this is it so far: import java.util.*; public class ProjectCS { public static void main(String[] args) { welcome
help please!!! T_T
help please!!! T_T  what is wrong in this?: import java.io.*; class...("please enter your name:"); name1= input.readline(); System.out.println("please... { String name1; String name2; System.out.println("please enter
Logic error? HELP PLEASE! :(
Logic error? HELP PLEASE! :(  Hello Guys! i have a huge problem. What... your saved Quick Quotes, please enter your Email Address...("emailAddress")) + " Please input a valid email address
Help please, some strange errors
Help please, some strange errors  Sorry about this messy formatting. As a beginner in java i got no idea which part of the code is creating... is causing that run-time errors? Any kind of help will be helpful to me. and let
help please
help please  hi i am done with register application using jsps servlets htmls. But i couldnt imp one thing that.. Wen u login to ur account browser... file.. Or atleast help me with code here.. I tried checking session alive
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades function computeGrade( ) { var hw, lab, midt, fin, avg; hw = parseFloat
Grid World project Run Error !! help please!!
Grid World project Run Error !! help please!!  i'm trying to make...) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) thank you...PLEASE HELP ME!!   ignore the comment " move to the next location of diagonal
Java Help Please
Java Help Please  I can't seem to figure out how to make this program, can some one help me please? It is due soon!! 4) Write a program that will take an input (Date object will contain fields for the month, day, and year - all
help please - Java Beginners
help please  i wrote this program but the function newLine dosnt work with me and i dont know where is exactly the error this is the code i wrote import java.io.*; import java.util.*; import java.lang.Integer
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement"); System.out.print("Year
need
need  i need a jsp coding based project plz help me
Need of ORM
Need of ORM  Why do you need ORM tools like hibernate
need of code
need of code  howto convert greyscale image to binary image in java
need coding
need coding  sir i need code for simple bank application in jsp please send it   sir i need the coding for simple bank application in jsp.   Please visit the following link: Jsp Bank Application
Need Suggistion
Need Suggistion  how to call a callable statement in our jSp page using Struts environment
urgent need
urgent need   Input a line. Count the number of words that start with a capital letter
need to Program
need to Program   Can any one help me on below How to insert more then one records in EXCEL Sheet using JSP
Need Project
Need Project  How to develop School management project by using Struts Framework? Please give me suggestion and sample examples for my project
need query
need query  hi sir , i am beginner to sql.i need a query so that it can be helpful to my project. i have four tables each containing different fruits with different amounts. i need a query in such a way that when i say some
 

 

 

DMCA.com