Question: How to retrieve data by using combo box value in jsp?

Ads

 
 
 

Share on Google+Share on Google+

Raja
How to retrieve data by using combo box value in jsp?
1 Answer(s)      7 years ago
Posted in : JSP-Servlet
Hi Friends,

When i click combobox value in jsp form page, it will diplay related value.... I am using only this page.. not get value from another page...
For Example, in Student.jsp... when i click student id in combo box, the related student name will be display. I can stored all student id stored in combo box from database.. by using select*from studentinformation;

But when i click combobox the related student name did not display...

On friend gave the follwing link

http://www.roseindia.net/jsp/comboSelect.shtml ull pointer exception

if i am trying null pointer exception will be occured.. I need immediately respose from u......




Ads
View Answers

February 24, 2010 at 3:34 PM


Hi i try the URL given above
http://www.roseindia.net/jsp/comboSelect.shtml
and i run that project with my settings
it works


I'm using enterprisedb ,and glassfish v2 and netbeans
change these settings to your settings and run app.

My sample table script is below.
CREATE TABLE "user"
(
"name" character varying(100),
eid character varying
)

--------code ------------------------------getuser.jsp----------------------------------
<%@ page import="java.sql.*" %>
<%
String emp_id = request.getParameter("emp_id").toString();
String data ="";

Connection conn = null;
String url = "jdbc:edb://127.0.0.1:5444/";;
String dbName = "nb";
String driver = "com.edb.Driver";
String userName = "enterprisedb";
String password = "OLIMPUS";

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

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select name,eid from public.user where name='"+emp_id+"'" ;

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
data = ":" + rs.getString(1)+" " + rs.getString(2) ;
}


out.println(data);
}
catch (Exception e) {
e.printStackTrace();
}
%>

---------------------------combobox.jsp------------------------------------
------------
<%@ page import="java.sql.*" %>
<html>
<head>
<style>
A:hover {text-decoration: none;

border: 0px;
font-size:14pt;
color: #2d2b2b; }
</style>

<link rel="stylesheet" type="text/css" href="datepicker.css"/>


<script type="text/javascript">
function showEmp(emp_value)
{
if(document.getElementById("emp_id").value!="-1")
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.jsp"
url=url+"?emp_id="+emp_value

xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}
else
{
alert("Please Select Employee Id");
}
}

function stateChanged()
{
document.getElementById("ename").value ="";
document.getElementById("emp_id").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

var showdata = xmlHttp.responseText;
var strar = showdata.split(":");

if(strar.length==1)
{
document.getElementById("emp_id").focus();
alert("Please Select Employee Id");
document.getElementById("ename").value =" ";
document.getElementById("emp_id").value =" ";

}
else if(strar.length>1)
{
var strname = strar[1];
document.getElementById("emp_id").value= strar[2];
document.getElementById("ename").value= strar[1];
}

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
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 Id</b></td><td>
<select name="semp_id" onchange="showEmp(this.value);">
<option value="-1">Select</option>
<%



Connection conn = null;
String url = "jdbc:edb://127.0.0.1:5444/";;
String dbName = "nb";
String driver = "com.edb.Driver";
String userName = "enterprisedb";
String password = "OLIMPUS";

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

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select name from public.user";

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
%>

<%
while(rs.next())
{
%>

<option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option>

<%
}
%>

<%

}
catch (Exception e) {
e.printStackTrace();
}

%>

</select>
</td></tr>


<tr><td ><b>Employee Id:</b></td><td><input type="text" name="emp_id" id="emp_id" value=""></td></tr>
<tr><td><b>Employee Name:</b></td><td><input type="text" name="emp_name" id="ename" value=""></td></tr>

</table>
</form>

<table border="0" width="100%" align="center">


<br>
<br>


</table>
</body>
</html>

Hope this helpful.
Best Regards.

Ads









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads