Home Answers Viewqa JSP-Servlet dynamic display

 
 


mohit
dynamic display
1 Answer(s)      2 years and 10 months ago
Posted in : JSP-Servlet

hi,
i want to display dynamic values in drop drown box in a jsp page.these values are in the form of arraylist's object which came form another servlet or bussiness logic after being validated in rdbms.hope u will understand what i have mentioned.plz reply soon....
View Answers

July 5, 2010 at 11:51 AM


Hi Friend,

Try the following code:

1)DataServlet.java:

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

public class DataServlet extends HttpServlet{
String page="/jsp/data.jsp";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/test";;
Connection connection=null;
ResultSet rs;
response.setContentType("text/html");
List dataList=new ArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "select name from data";
Statement s = connection.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
dataList.add(rs.getString("name"));
}
rs.close ();
s.close ();
}
catch(Exception e){
System.out.println("Exception is ;"+e);
}
request.setAttribute("data",dataList);
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
if (dispatcher != null){
dispatcher.forward(request, response);
}
}
}

2)data.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<head>
<title>Data Page</title>
</head>
<body>
<select>
<% List data= (List)request.getAttribute("data");
for(int i=0;i<data.size();i++)
{
%>
<option value="<%=data.get(i).toString()%>"><%=data.get(i).toString()%></option>
<%
}%>
</select>
</body>
</html>

Thanks









Related Pages:
dynamic display - JSP-Servlet
dynamic display  hi, i want to display dynamic values in drop drown box in a jsp page.these values are in the form of arraylist's object which came form another servlet or bussiness logic after being validated
dynamic polymorphism
dynamic polymorphism  give an example for dynamic polymorphism?   Dynamic polymorphism is where a class overrides a superclass method... seen at runtime, so they are considered dynamic. Here is an example
dynamic image change javascript
dynamic image change javascript  How to display images in JavaScript dynamically
Dynamic retrieval od data from database and display it in the table at jsp
Dynamic retrieval od data from database and display it in the table at jsp  Hi friends.... Am creating software for chit fund.. I want to display...; Here is a jsp code that retrieves the data from the database and display
dynamic pagination in jsp - JSP-Servlet
dynamic pagination in jsp  i am unable to display the data in multiple pages. I am gettting data from the database from the javaBeans to jsp by vectors... but i am unable to displaying them in jsp 15 records per page
JSP: Dynamic Linking - JSP-Servlet
JSP: Dynamic Linking  Hi I am fetching data as a search result from... inside your result set loop to provide them a dynamic link. JSP Code...;Thank you for the answer. but how can i display all the details of that id
JSP:Dynamic Linking - JSP-Servlet
JSP:Dynamic Linking  Hi This is extension to my previous question: " I am fetching data as a search result from database and displaying... having an anchor link .You click on it and display the full details on the next
dynamic content on the inbox page - Java Beginners
dynamic content on the inbox page  sample java code to display the dynamic content on the inbox page.  Hi friend, Plz give details with source code where you having the problem : Thanks
Spring AOP Dynamic Pointcut
Dynamic Pointcut Dynamic Pointcuts takes method arguments, as well as static... method stub System.out.println("Dynamic Cheching for " + method.getName...); beanProxy.greetMethod(); } } When you run this application it will display message
How to insert dynamic textbox values into database using Java?
of dynamic textboxes with Name and Address will display....Now I want to Insert...How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2
DYNAMIC BINDING
DYNAMIC BINDING  WHAT IS DYNAMIC BINDING
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help me. I am trying to create a dynamic table with checkboxes. Data are accessed...){ return c==0; } //used to display checkbox else it will show true
Java Swing dynamic Combobox
Java Swing dynamic Combobox In this section, you will learn how to display the data in one combobox related to another combobox. For this, we have created two combo boxes. In the first combobox, we have added four items. When the user
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
dynamic report
dynamic report  i need complete code for generating dynamic report in jsp
dynamic retrivel of data from mysql database in table format at jsp
dynamic retrivel of data from mysql database in table format at jsp  ... the data from database and display it as table format in jsp... For example, i have... of A1 should be retrived from database and display it in the respective textbox
dynamic polymorphism
dynamic polymorphism  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism
Dynamic keyword
Dynamic keyword  hi....... What is the dynamic keyword used for in flex? give me the answer ASAP Thanks  Ans: Dynamic keyword-> Specifies that instances of a class may possess dynamic properties added
dynamic retrival of data from mysql database to dropdownlist in jsp
dynamic retrival of data from mysql database to dropdownlist in jsp  ... database to the dropdownlist in jsp. Example: 1st i want to display the list... be retrived from the database and display in the textbox as default value... pls its
dynamic textfields
dynamic textfields  Hi, I am a fresher and joined recently in one company. they gave me a desktop application project using swings.here is my detailed spec Screen 1 - The user enters the ingredients from a food product, saves
Dynamic form
Dynamic form  I need to make a dynamic form using jsp for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys ), and also a radio button wich once
dynamic jquery statement
dynamic jquery statement  dynamic jquery statement
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys from a dtabase ), and also a radio
dynamic calender
dynamic calender  hi i need the code to "insert date using GUI"   Hi Friend, Try the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; class DatePicker{ int month
dynamic query
dynamic query  DECLARE QUERY VARCHAR2(32767); FIN_QUERY VARCHAR2(32767); CURSOR C IS (select distinct PORTFOLIO from MPE_TEST1); CURSOR C2 IS SELECT DISTINCT PORTFOLIO_LEVEL, PORTFOLIO FROM MPE_TEST1 ORDER
PHP Dynamic CheckBox
PHP Dynamic CheckBox  Help with Dynamic Checkbox in PHP
php dynamic array checking
php dynamic array checking  php dynamic array checking
php dynamic array checking
php dynamic array checking  php dynamic array checking
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
Activity display dynamically depend on the locale on Struts
Activity display dynamically depend on the locale on Struts  i want to display activities dynamically which can be increase or decrease on struts 2..._fr.properties: activity.name=activity_fr for dynamic, i am using array list
display records with images problem - JSP-Servlet
display records with images problem  hello, i am developing HR application whereby i want to display employee records and their pictures on web... with a unique id. Also i wrote i jsp that link to servlet in order to display
how to add dynamic data
how to add dynamic data  how to add dynamic data to an existing web application
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages
dynamic web pages in html
dynamic web pages in html  How to create Dynamic web pages in HTML
static page and dynamic pages?
static page and dynamic pages?  what is the diff between static page and dynamic pages
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages adv and disadv
Dynamic include jsp
Dynamic include jsp  I need dynamic include jsp page with an example
Dynamic Array iPhone
Dynamic Array iPhone  Dynamic Array iPhone How can i add NSMutable array dynamically into my iPhone App
Dynamic polymorphism - Java Beginners
Dynamic polymorphism  Develop with suitable hierarchy, classes for point, shape, rectangele, square, circle,ellipse, triangle, polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.. Thanks
Dynamic Polymorphism - Java Beginners
Dynamic Polymorphism  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.? Thanks
Dynamic html examples
Dynamic html examples  Hi, What is Dynamic HTML? Explain with dynamic html examples. Thanks   Hi, DHTML stands for Dynamic HTML and is uses the HTML, JavaScript, DOM, & CSS in a program. Following is very simple
Dynamic-update not working in Hibernate.
Dynamic-update not working in Hibernate.  Why is dynamic update not working in hibernate?   Dynamic-update is not working. It means when you are running your update, new data is added in your table in place
Dynamic pages - Struts
Dynamic pages  I want to recreate a page on click and then enter data in my database via struts1.1 please help me what can i use or what help i can get from
Creating Dynamic Tree
Creating Dynamic Tree   Creating Dynamic Tree: I have to build a tree structure with the following data lets say that with this data childId parentId 1 - 0 (lets say this is root) 2 - 1 3 - 1 4 - 3 5 - 3 6 - 5 7 - 6 all I need
dynamic select box
dynamic select box  hello friends i created a form and details of city & locations have to be come from database. if city hyderabad chosen then locations of hyderabad only appear in location selectbox.plz send code it is more
Hibernate : Dynamic-insert
This tutorial contains description of Hibernate dynamic-insert
need dynamic image example
need dynamic image example  struts 2 img example for a dynamic image.. one that the user of the website uploads. To be more clear on what I am doing. I am creating a profile for a user and the user is uploading his image which I
problem with dynamic url
problem with dynamic url  Hello! I was asked to implement a dynamic url code below to a html template I designed. I am a web designer, and although I understand the code, there is something wrong with it, or maybe I didn't do

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.