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



Home Answers Viewqa Struts Java Answers
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


naidu
Java Answers
1 Answer(s)      3 years and a month ago
Posted in : Struts


How to Dispaly  databsae records in my jsp page using collections  Java Class

Advertisement
View Answers

August 24, 2011 at 10:24 AM


1)BeanServlet.java:

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

public class BeanServlet extends HttpServlet{
    protected void doPost(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"));
}
req.setAttribute("data", list);
        RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
        rd.forward(req, res);
}
catch(Exception e){
}
    }
}

2)beandata.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<body> 
<table border="1" width="303">
<tr>
<td width="119"><b>Name</b></td>
<td width="168"><b>Address</b></td>
<td width="119"><b>Contact no</b></td>
<td width="168"><b>Email</b></td>
</tr>
<% Iterator itr;%>
<% List data=(List)request.getAttribute("data");
for(itr=data.iterator(); itr.hasNext(); ){
%>
<tr>
<td width="119"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
</tr>
<%}%>
</table>
</body>
</html>


Related Tutorials/Questions & Answers:
Java Answers
Java Answers  How to Dispaly databsae records in my jsp page using collections Java Class   Visit Here
Java Answers
Java Answers  How to Dispaly databsae records in my jsp page using collections Java Class   Visit Here
Advertisements
Java Answers
Java Answers  How to Dispaly databsae records in my jsp page using collections Java Class   Visit Here   For getting records from database to java collections you want to do following steps. 1.Declare
Java Answers
Java Answers  How to Dispaly databsae records in my jsp page using collections Java Class   1)BeanServlet.java: import java.io....){ } } } 2)beandata.jsp: <%@page language="java" import="java.util.*" %> <
Java interview questions and answers
Java interview questions and answers   what is garbage collection? What is the process that is responsible for doing that in java? Ans.Reclaiming... in Java? Ans. Runtime.getRuntime().exec(?.) 5.What is the basic difference
oop answers - Java Beginners
. Write a Java statement that prints the values of the instance variables of x. i. Write a Java statement that creates the XClass object t and initializes
Core Java Interview questions and answers
Core Java Interview questions and answers  ... and answers in one place. These Core Java Interview Questions are supported... the answers. We are constantly trying to provide best Core Java Interview questions. You
java apptitude question and answers - Java Beginners
java apptitude question and answers  i want java appititude question and answers  Hi Friend, Please visit the following link: http://www.roseindia.net/interviewquestions/ Thanks
Plz give the answers - Java Interview Questions
), is the number itself. Write a JAVA program to find all perfect numbers between 2... information,Examples and tutorials on java visit to : http://www.roseindia.net/java/ Thanks
Software Questions and Answers
from within Java program. JMS - JMS questions and answers...Software Questions and Answers       View Software Questions and Answers online Discuss Software
Questions and Answers Help
://www.roseindia.net/answers/viewqa/Java-Beginners/11976-Java-Hello-World-code...Questions and Answers Help      ... programmers to give precise answers to your question. Describe your question
Questions and Answers Help
://www.roseindia.net/answers/viewqa/Java-Beginners/11976-Java-Hello-World-code...Questions and Answers Help      ... programmers to give precise answers to your question. Describe your question
Outsourcing - Answers to Critism, Outsourcing Answers Critics
Outsourcing - Answers to Criticism, Outsourcing Answers Critics Introduction As the outsourcing juggernaut rolls on, business analysts have come up with arguments favoring and criticizing it. Cost savings
I want this jsp answers
I want this jsp answers    How can we declare third party classes and interfaces inside our jsp page? How can we declare and definr global variables... jsp page, server can develop a .java file for a particular jsp page or not? What
I want this jsp answers
I want this jsp answers    How can we declare third party classes and interfaces inside our jsp page? How can we declare and definr global variables... jsp page, server can develop a .java file for a particular jsp page or not? What
Software Questions and Answers
the answers of the questions asked. JavaMail - Java API to send...Software Questions and Answers View Software Questions and Answers online Discuss Software development questions, ask your questions and get answers
plz Help me find the correct programs answers
INDICA" and "TATA NANO" respectively. Plz mail me your answers
Interview Questions and Answers
Interview Questions and Answers   ... that there cannot be just one answer to them. Your answers depend a lot on your particular... such questions, rather than specific answers. Remember, what you say makes only
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter specific input numbers and the program will be able to sort the given numbers
please help me to answers this question about C++.....huuhuhuhu
please help me to answers this question about C++.....huuhuhuhu  1) Write a full program for the bubble sort algorithm. User is required to enter specific input numbers and the program will be able to sort the given numbers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
java - Java Beginners
java  simple java program questions with answers
java
java  pls send me some java basic interview questions with answers
Common Interview Questions and Their Answers.
Common Interview Questions and Their Answers... important part of these is your answers. Also make sure to check how long you speak on each occasion. Do not talk for more than two minutes at a stretch. The answers
Question Answer
, please follow these steps: Only post your Java or Open Source or technical... and email address is mandatory for the users. The query relating to Java or java relating fields will only be responded. Posting filthy
Question-Answer Guidelines
and get their answers? RoseIndia Q&A service is only for troubleshooting the Java... guidelines: Do this: The user must post the query relating to only Java... to declare theirs' existing and true email addresses in which the answers
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
hint - Java Interview Questions
hint  Dear roseindia, i want the java interview question and the corresponding question answers.   Hi Friend, Please visit... of interview questions and their answers. Thanks  thanks for your
java
java  Please send me some question and answers regarding interview .....   Hi Anitha, Please go through the below blog, you will get some information related to Java like. http://www.roseindia.net/java/ All
 

 

 

DMCA.com