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



Home Answers Viewqa JSP-Servlet fetch values in dropdown

Have Programming Question? Ask it here!
 
 
 


megha singhal
fetch values in dropdown
2 Answer(s)      2 years and 5 months ago
Posted in : JSP-Servlet


in my application i want fetch dropdown values in jsp page through servlet. means i have to fetch the database fields values in array variable of servlet and then i have to print those values in dropdown.


Advertisement
View Answers

April 10, 2012 at 5:19 PM


1)BeanInServlet.java:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BeanInServlet extends HttpServlet{
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException{
        ArrayList list=new ArrayList();
try{
     Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from employee");
           while(rs.next()){
               list.add(rs.getString("name"));
               list.add(rs.getString("address"));
               list.add(rs.getString("contactNo"));
               list.add(rs.getString("email"));

}
}
catch(Exception e){}

        req.setAttribute("data", list);
        RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
        rd.forward(req, res);
    }
}

2)beandata.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<body> 
<select>
<option value="Select">Select</option>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); ){
%>
<option value="<%=itr.next()%>"><%=itr.next()%></option>
<%}%>
</select>
</body>
</html>


April 10, 2012 at 5:41 PM


but your jsp page code is not working there is any problem in the following line ""



Related Tutorials/Questions & Answers:
fetch values in dropdown
fetch values in dropdown  in my application i want fetch dropdown values in jsp page through servlet. means i have to fetch the database fields values in array variable of servlet and then i have to print those values in dropdown
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
Advertisements
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
store dropdown box values in database server
store dropdown box values in database server  how to store dropdown box values in database server in jsp
how to fetch values from .properties to a html file
how to fetch values from .properties to a html file  I have a .properties file with some key value pairs in it. I need to fetch the values from this .properties file into a html file.Please let me know how to do
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am trying following String query = "select * from LTCINFO.PERSONS"; st1
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit and delete option on each row as if i am trying following String query = "select
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html... to insert all selected values in data base correspondent to each like if user
getting dropdown values using apache commons in servlet
getting dropdown values using apache commons in servlet  i want to get dropdown values in my program in order to merge the string to my file path so that the path will change dynamically according to user input.iam new to apache
How to change the dropdown values based on other dropdown in itext pdf or in any other?
How to change the dropdown values based on other dropdown in itext pdf or in any other?  How to change the drop down values based on another drop down? For eg: If we select one county, that related states only come, if we select
How to fetch entries/values from database to a jsp page one by one?
How to fetch entries/values from database to a jsp page one by one?  I have a table in Microsoft SQL server Management Studio with two columns title and data and each column has 10 enteries. I have a jsp page on which i want
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values... this code it is adding one more value to the dropdown box and showing as selected. so if I have 5 values in the dropdown this selected one is added as 6th values
dropdown
dropdown  how to hide textbox field when i deselect from select dropdown
dropdown
dropdown  I have a dropdown having 2 options-"Open"& "closed".When i select "open" option the related rows of data are retrieved from database and same with the other option.My database is Mysql and coding in PHP
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values..., This is for Updating. I had two SQL queries one for only selected values the user has choosen before and the second SQL query to show all the values. Iwas
Ajax Dropdown
Ajax Dropdown  hi I have One Dropdown that contains 2 options assume A and B,if i select A option then samepage one more Dropdown is their it should display values in german language using DWRUtil Parameter values in ajax. Only
JSP Get Data Into Dropdown list From Database
JSP Get Data Into Dropdown list From Database In this section we will discuss about how to fetch data dynamically into the dropdown list in JSP. This tutorial explains you that how to fetch data from database and set
dropdown box
dropdown box  i need to have country,state and city in drop down box using ajax and use db2 database   Have a look at the following link: JSP dependent dropdown
populate dropdown box
populate dropdown box  hi, Is there any ways in which i can populate my dropdown menu with values from 1 to n (n = the value stored in database... item in dropdown menu is 10 then the second dropdown box should contain values
jsp dropdown - JSP-Servlet
to use this textbox value to fetch values from database...jsp dropdown  print dropdown selected value in same page without refreshing page in jsp....   Hi Friend, Try the following code: 1
Dropdown code to retrieve result from oracle database
need to fetch the result when the dropdown is chosen.Can anyone please help me... that will retrieve values from the database into dropdown. As the user choose any option from the dropdown, corresponding values will get displayed in the textboxes
dropdown cacheing
dropdown cacheing   I need code to create cache for load drop down list from db in struts1 example
DropDown list
DropDown list  how to get mysql database values into dropdown usign java servlet and ajax?   Here is a jsp code that displays the database values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>
fetch url in php - PHP
fetch url in php  How to Fetch URL in PHP
DropDown Menu
DropDown Menu  Hello, i have a program that can view,add,delete... me draw to your my mind my program.. in my homepage which i have a dropdown... is the problem.. for example; if i select page 1 in my dropdown menu, and click
mysql_fetch_object and mysql_fetch_array.
mysql_fetch_object and mysql_fetch_array.  What is the difference between mysqlfetchobject and mysqlfetcharray?   Hi friends, MySQL fetch object will collect first single matching record where mysqlfetcharray
dropdown - JSP-Servlet
dropdown  i want to use dropdown select value in query-string in same page.. Using selected 'name' want to fetch details of that person from database.. without using Ajax...  Hi Friend, Try the following code
jsp dropdown - JSP-Servlet
jsp dropdown  in my table there are 3 fields named orderid ,itemname, itemqty. i want code that fetch orderid in dropdown... on select dropdown get all items list of that orderid... there are multiple items at one orderid
struts dropdown list
struts dropdown list   In strtus how to set the dropdown list values from database ? I have a ArrayList object and set this object in dropdown jsp page using struts ? please send me jsp code... sample code: **Action
Dependant Dropdown Lists
Dependant Dropdown Lists  Hello, I'm trying to create 2 dropdown lists. When the visitor chooses one option from the 1st list it will automatically update the 2nd dropdown. Ive already found some code which i edited but still
dropdown list in jsp
dropdown list in jsp  hai, i have static dropdown list.. i want to get the selected value in string variable without jsp regards asha
html dropdown not working firefox
html dropdown not working firefox  I am writing a Dropdown code in HTML which is not working in firefox. What could be the reason as it's perfectly working in IE and Crome. Thanks
creating dropdown lists in jsp
creating dropdown lists in jsp  i want to create two dropdown list which are dependent that is the first box choice have to evaluate the second boxs options
Dropdown menus onchange atribute
from database and store it into dropdown list. On selecting the value from the first dropdown, the values will get stored into another dropdown from the database...Dropdown menus onchange atribute  Can I know how do we get the drop
What is the difference between mysql_fetch_object and mysql_fetch_array?
What is the difference between mysql_fetch_object and mysql_fetch_array?  What is the difference between mysqlfetchobject and mysqlfetcharray
SQL fetch value
SQL fetch value  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d %M
What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?  What are the differences between mysqlfetcharray(), mysqlfetchobject(), mysqlfetchrow
ajax+dropdown+table format
ajax+dropdown+table format  HI, i am looking for an ajax application which must contain two dropdown list.In first dropdown if i select a manager name from the first dropdown all the reporties under the selected manager should
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
how to fetch data from servlet ????
how to fetch data from servlet ????  how to fetch data from servlet
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <...,choice) VALUES('"+Id+"','"+Name+"','"+Home+"','"+Location+"','"+Gender...; } @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@222 how to fetch
dropdown - JSP-Servlet
dropdown  i want to use dropdown select value in query-string in same page.. Using selected 'name' want to fetch details of that person from database..  Hi Friend, Try the following code: 1)ajaxExample.jsp
Retrieval of Dropdown list
... for eg, let A1,A2,A3,A4 be the values in dropdown.. if i click A1...Retrieval of Dropdown list  Hi frnds... Am having problem... dropdown.. Am not able to retrive the name for further process... Pls check
query to fetch the highest record in a table
query to fetch the highest record in a table  Write a query to fetch the highest record in a table, based on a record, say salary field in the empsalary table
php mysql fetch array example
php mysql fetch array example  How to fetch data from mysql and store it into an array in PHP? Please post an example. Thanks in Advance
PDO Fetch Execute
PDO Fetch Mode: We have studied before in the earlier tutorials that how to connect with a database and how to fetch data from the tables, in many times we... a technique called FETCH, which is used with the PDOStatement object. PDO
PHP SQL Fetch
PHP SQL Fetch       PHP SQL Fetch is used to fetch the records from Mysql database to PHP... The Tutorial illustrate an example from PHP SQL Fetch. To understand and grasp
Hibernate Criteria Fetch Size Example
Hibernate Criteria Fetch Size Example  I want example of Hibernate Criteria Fetch Size. Share me the best example program and tutorial of Hibernate Criteria Fetch Size. Thanks   Best Example of Hibernate Criteria Fetch
Advertisements
 

 

 

DMCA.com