Abhishek Ghosh
Fetch the data using jsp standard action
2 Answer(s)      2 years and 9 months ago
Posted in : JSP-Servlet

I want the code of fetch the data from the database & show in a jsp page using jsp:usebean in MVC model 2 architecture. Suppose after login a user can view his/her details which he entered at the time of registration.

Advertisement
View Answers

July 6, 2012 at 3:12 PM


Here is an application that retrieves the data from the database through java bean and display it in jsp page through servlet.

1)EmpBean.java:

package form;
import java.sql.*;
import java.util.*;
public class EmpBean {

public List dataList(){
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){}
return list;

}
}

2)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{
        form.EmpBean p = new form.EmpBean();
        List list=p.dataList();

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

3)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>

For more information, visit the following link:

http://www.roseindia.net/jsp/servlet-jsp-data-list.shtml



July 7, 2012 at 1:09 AM


In the beandata.jsp you are using scriptlet tag(<% %>).But I am wanting this should be done using jsp:usebean..means scriptless jsp..How can I do that? Thanks in advance










Related Tutorials/Questions & Answers:
Fetch the data using jsp standard action
Fetch the data using jsp standard action  I want the code of fetch the data from the database & show in a jsp page using jsp:usebean in MVC model... that retrieves the data from the database through java bean and display it in jsp page
standard action - JSP-Servlet
or a standard tag. For Example : Action may display an output or write some value... has attributes with their values. Some Standard action tags: :- The forward action passes the request to another page,page may be a html page or jsp page
Advertisements
Standard Action "jsp:plugin"
Standard Action <jsp:plugin> In this Section, we will discuss about standard action "jsp:plugin" & their implementation using a example. The <jsp:plugin> action is use to download a plugin (an Applet or a Bean
Standard Action "jsp:param"
Standard Action <jsp:param> In this Section, we will discuss about "jsp:param" standard action & their utilization with a example... by using <jsp: forward> tag. Inside this tag we have used the tag <jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
JSP Standard Action 'jsp:useBean'
JSP Standard Action <jsp:useBean> This action let you use java bean in a JSP page. This action instantiates or locates a Bean with a specific name... standard Actions :<jsp:setProperty> & <jsp:getProperty>
how to fetch data fron facebbok using spring batch and hibernate ?
how to fetch data fron facebbok using spring batch and hibernate ?  how to fetch data from facebbok using spring batch and hibernate ? Means i have to get all details of data from one source like facebook using id ans save all
fetch record from oracle database using jsp-servlet?
fetch record from oracle database using jsp-servlet?  how can i fetch data from oracle database by using jsp-servlet. i'm using eclipse, tomcat server and oracle database and creating jsp pages and also using servlet
JSP Standard Actions
JSP Standard Actions In this section, we will learn about JSP standard Action & their elements with some examples. JSP Standard action are predefined... at the exact time the JSP page is requested by a browser. An action can, for instance
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  hello!!! I am building a attendance sheet in which, I am getting data from one jsp form and want inserting it into my mysql database table. but i am having
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <...;/h1> <center> <form action="hit" method="POST">..." content="text/html; charset=UTF-8"> <title>JSP Page</title>
how to fetch data from servlet ????
how to fetch data from servlet ????  how to fetch data from servlet
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
Displaying grouped data using Action script in AdvancedDataGrid
Displaying grouped data using Action script in AdvancedDataGrid: In this example you can see how we are create a Grouped Data using Action script...:Script> <s:Panel title="Displaying grouped data using
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
Accessing Jqxgrid data in Controller layer using JSP
Accessing Jqxgrid data in Controller layer using JSP  I am using Keyboard Navigation jqxgrid. I am able to bind the grid by passing data from controller layer using JAVA. What i actually require is to fetch the data which
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
to fetch data from ms word and storing into database
to fetch data from ms word and storing into database  i want to know how to fetch datafields from ms word and storing into database??? please answer soon .its urgent
JSP Action Tag
JSP Action Tag   Defined JSP Action Tag ?   Action tag... JSP action tags to either link to a Java Bean set its properties, or get its properties. syntax of Action Tag : <jsp:action attributes /> The most
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
Data fetch from multiple SQL tables - Hibernate
Data fetch from multiple SQL tables   I am in the process of writing my first hibernate application. I have a sql query that fetches data from multiple tables using left and right outer joins. I need to convert this JDBC data
how to fetch the record using AJAX? - Ajax
how to fetch the record using AJAX?  Can anyone tell me how to fetch the records from database using Ajax
how to forward select query result to jsp page using struts action class
how to forward select query result to jsp page using struts action class  how to forward select query result to jsp page using struts action class
fetch data from ms acces - Swing AWT
fetch data from ms acces  How do i fetch back AUTO generated key from MS ACCESS table after inserting data through the java panel.... Please Help...(); ResultSet rs=st.executeQuery("select * from data "); while(rs.next
Select tag to fetch data from oracle database
Select tag to fetch data from oracle database  I created a select box having more than one menus in the select box such as regnno, address and name...?? If using strut it has to be completed then also plzzzz tell me
JSP Forward action
JSP Forward action  Jsp forward action tag examples
JSP Get Data Into Dropdown list From Database
about how to fetch data dynamically into the dropdown list in JSP... fetching of data into the dropdown list in JSP using Eclipse IDE and the Tomcat 7... data from the database and set it into the dropdown list in JSP using MySQL
Jsp Action Tags
Jsp Action Tags  how can i use jsp forward action tag?i want examples
RADIO FROM JSP TO ACTION.
RADIO FROM JSP TO ACTION.  Hi frds, how to get the selected multiple radio button values from jsp to action