Fetch the data using jsp standard action

Ads

 
 

Share on Google+Share on Google+

Abhishek Ghosh
Fetch the data using jsp standard action
2 Answer(s)      5 years and 2 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.

Ads
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:

<[email protected] 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


Ads









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
How to Fetch Data using dropdown option
How to Fetch Data using dropdown option   sir maine jsp pr ek login page banaya jismain branch ka option hai. main agar first dropdown main first... uski table main hi data insert/fill ho
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>
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
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
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
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
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
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
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
get data between date using jsp with msaccess
get data between date using jsp with msaccess  hi, urgently i need program for get data between date using jsp with MsAccess database.plz any one can help me.thanks for anyone replay with regards c.b.chellappa
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
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
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data
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  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <...;/h1> <center> <form action="hit" method="POST">..." content="text/html; charset=UTF-8"> <title>JSP Page</title>
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
JSP Forward action
JSP Forward action  Jsp forward action tag examples
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what... method="post" action="http://localhost:8080/examples/jsp/insert.jsp"> <..."; // declare a connection by using Connection interface
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <[email protected] uri="http://struts.apache.org/tags-html" prefix="html"%> <...*; import org.apache.struts.action.*; public class SearchAction extends Action
Jsp Action Tags
Jsp Action Tags  how can i use jsp forward action tag?i want examples
Retrieve data from databse using where in JSP
Retrieve data from databse using where in JSP  Hi, can somebody help me? I have a jsp page. in that i want to get data from the database where username is matched. i tried it. but can't get the output. here is the code. please
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one combo box is there and another filed is version of the server(like 1.0,2.0) like
Source Code for Implementing Search Feature in JSP using Java action/Servlet - JSP-Servlet
Source Code for Implementing Search Feature in JSP using Java action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? My query is: SELECT @rownum:[email protected]+1 'rownum', X
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use