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



Home Answers Viewqa EJB DataGrid without DataBase

Have Programming Question? Ask it here!
 
 
 


Manish Grover
DataGrid without DataBase
2 Answer(s)      3 years and 3 months ago
Posted in : EJB


I want display list of data without using database. Ex- Employee have some elements like- name, sex, place, designation. I have to display the content of these elements but without having this information in database, but this can be present in java file.


NAME SEX PLACE DEGREE
Manish Male Delhi CA Aman Male Delhi MBA

above you can see, it can show like this. The Data of manish and aman will be in java file not in Database. Using JSP for frontend and java file for backend, no database.


Advertisement
View Answers

April 28, 2011 at 12:53 PM


1)PaginationServlet.java:

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

public class PaginationServlet extends HttpServlet {
    int offset;
    int length;
    List list;

    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        int maxEntriesPerPage = 2;
        int page = 1;
        String pageNumberValue = request.getParameter("pageNumber");

        if (pageNumberValue != null) {
            try {
                page = Integer.parseInt(pageNumberValue);
                System.out.println("Page Number:" + page);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        int offset = maxEntriesPerPage * (page - 1);
        TestList(offset, maxEntriesPerPage);

        HttpSession httpSession = request.getSession();
        httpSession.setAttribute("pages", getPages());
        httpSession.setAttribute("studentDetails", getListByLength());

        RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/paging.jsp");
        dispatcher.forward(request, response);
    }
    public void fillList() {
        list = new ArrayList();
        list.add(new Student("A", "Delhi", 25, "Btech"));
        list.add(new Student("B", "Mumbai", 26, "Mtech"));
        list.add(new Student("C", "Kolkata", 27, "MSC"));
        list.add(new Student("D", "Chennai", 28, "MBA"));
        list.add(new Student("E", "Hyderabad", 23, "MCA"));
        list.add(new Student("F", "Agra", 24, "MBBS"));
        list.add(new Student("G", "Shimla", 26, "BDS"));
        list.add(new Student("H", "Lucknow",25,"MCom"));
    }
    public void TestList(int offset, int length) {
        this.offset = offset;
        this.length = length;
        fillList();
    }
    public ArrayList getListByLength() {
        ArrayList arrayList = new ArrayList();
        int to = this.offset + this.length;
        if (this.offset > list.size())
            this.offset = list.size();
        if (to > list.size())
            to = list.size();
        for (int i = this.offset; i < to; i++) {
            arrayList.add(list.get(i));
        }
        return arrayList;
    }
    public List getPages() {
        List pageNumbers = new ArrayList();
        int pages = list.size() / this.length;
        if (list.size() % this.length != 0) {
            pages = pages + 1;
        }
        for (int i = 1; i <= pages; i++) {
            pageNumbers.add(new Integer(i));
        }
        return pageNumbers;
    }
}


April 28, 2011 at 12:55 PM


continue..

2)Student.java

package form;
import java.io.*;

public class Student implements Serializable {

    private String name;
    private String address;
    private int age;
    private String degree;

    public Student(String name, String address, int age,String degree) {
        this.name = name;
        this.address = address;
        this.age = age;
        this.degree = degree;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getDegree() {
        return degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }

}

The above java class is a bean and should be located inside /classes/form/Student.

3)paging.jsp:

<%@page import="java.util.List"%>
<%@page import="form.Student"%>
<html>
<h1>Pagination</h1>
<%
    List list = (List) session.getAttribute("studentDetails");
    List pageNumbers = (List) session.getAttribute("pages");
%>
<table border="1">
    <tr><th>Name</th><th>Address</th><th>Age</th><th>Degree</th></tr>
    <%
        for (int i = 0; i < list.size(); i++) {
        Student st = (Student) list.get(i);
        %>
                <tr>
                <td><%=st.getName()%></td>
                <td><%=st.getAddress()%></td>
                <td><%=st.getAge()%></td>
                <td><%=st.getDegree()%></td></tr>
        <%
        }
        %>
        <td colspan="4" align="right">
        <form method="get" action="../PaginationServlet">
        <table>
            <tr>
                <%
                    for (int i = 0; i < pageNumbers.size(); i++) {
                %>
                <td><a href="/examples/PaginationServlet?pageNumber=<%=pageNumbers.get(i)%>"><%=pageNumbers.get(i)%></a></td>
                <%
                    }
                %>
            </tr>
        </table>
        </form>
        </td>
    </tr>
</table>
</html>


Related Tutorials/Questions & Answers:
DataGrid without DataBase
DataGrid without DataBase  I want display list of data without using database. Ex- Employee have some elements like- name, sex, place, designation. I have to display the content of these elements but without having
datagrid
datagrid   please send datagrid in jsp lot fields including date
Advertisements
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
Pagination without using database in php
Pagination without using database in php  How can I show multiple images in multiple rows with pagination in php
Designing a Database with a junction table or without it?
Designing a Database with a junction table or without it?  Designing a group of table with, where many tables reference single parent table. In that case is it a better option to create a junction table to maintain
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
connect database without specifying dsn name in java
connect database without specifying dsn name in java  How can i connect the database with my application without specifying the dsn name by using jdbc & odbc..... i have saw this code on the web-site try
jsp-datagrid
jsp-datagrid  hello sir.....i have 20 records in my database and i am showing those data in datagrid view but now i want to show 10 data in one page... option in my datagrid view with 1,2 pages....plz help me...awaiting for your
jsp-datagrid
jsp-datagrid  hello sir.....i have 20 records in my database and i am showing those data in datagrid view but now i want to show 10 data in one page... option in my datagrid view with 1,2 pages....plz help me...awaiting for your
DataGrid in flex
DataGrid in flex  Hi.... Please tell me What is the data type of the dataprovider property in DataGrid? please give an small example for that.... Thanks
DataGrid in flex
DataGrid in flex  Hi..... Please tell me about DataGrid extends which class? please give me the syntax......... Thanks
datagrid including combobox
datagrid including combobox  please send datagrid in jsp using mysql database based on id in the datagrid select each record and also update record with available to old values updation is done in form wise. using combo box
editable datagrid
editable datagrid  How to create a editable datagrid in jsp,struts1.3,glassfish v2.x application server and database oracle using netbeans6.8 ide?   Hi Friend, Please visit the following link: http://www.roseindia.net
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
DataGrid in flex
DataGrid in flex  Hi.... What kind of data grids you can create through Flex applications? please tell me about the datagrid so i can implement it in my application .... Thanks
DataGrid in flex
DataGrid in flex  Hi....... I want to know about How do you access methods in DataGrid from external itemRenderers? please give an example so i can clearly understand.... Thanks
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
How to save form fields into the MySql Database without submit button in jsp?
How to save form fields into the MySql Database without submit button in jsp?  I want to store user inputs into the database using javasccript or ajax or jqury but without submit button. Form Contains three fields
Datagrid not working
Datagrid not working  The code here is working fine, apart from... the datagrid tag gives an error saying that the items attribute does not accept ant... This works fine for datagrid but then the javascript for drop down menu stops
ArrayCollection in DataGrid
ArrayCollection in DataGrid  Hi.... I want to know about What are the advantages of using arraycollection as a dataprovider instead of array in DataGrid? please give the ans ASAP....... Thanks
DataGrid in flex
DataGrid in flex  Hi.... please provide the solution of that problem When I have only a single record, why doesn't it appear in my DataGrid? please give an example Thanks  Ans: This is a caused in flex
DataGrid in flex
DataGrid in flex  Hi........ Please provide the solution of that problem When I add or modify an item in my dataProvider, why doesn't it show up in my DataGrid? Thanks in advance  Ans: When you work
dyanamic upload of images using struts without database connection
dyanamic upload of images using struts without database connection  I want to upload images dynamically with out using data base..and want to create image for every user in my db
DataGrid ItemRenderer
DataGrid ItemRenderer  Hi... I have a datagrid which contains a Spark dropdownlist that needs to obtain dynamic data. The datagrid uses a separate..." backgroundColor="#000000"> <mx:DataGrid id="myDG" dataProvider="{myDP
datagrid search - Hibernate
datagrid search  Hi friend, i have displayed a datagrid using jsp but i need a search option in that which is used to display and sort...;Hi Friend, Do you want to get sorted data from the database along
jsp-datagrid
jsp-datagrid  hello sir...i have one view page in which edit and delete option are there in a datagrid view and i want to show data in page wise... code retrieves all the data from the database table and stored it into html table
jsp-datagrid
jsp-datagrid  hello sir...i have one view page in which edit and delete option are there in a datagrid view and i want to show data in page wise(pagination)...with previous and next links....i am also attaching my code for your
jsp-datagrid
jsp-datagrid  hello sir...i have one view page in which edit and delete option are there in a datagrid view and i want to show data in page wise(pagination)...with previous and next links....i am also attaching my code for your
How can i write a datagrid coding - Java Beginners
How can i write a datagrid coding  Hi, I want make a datagrid..plz send me datagrid coding using mysql database and jsp..plz tell me brief description about grid how can i connect datagrid with database. Thanks
How sql Queries possible in DAO without creating Database connections - Java Beginners
How sql Queries possible in DAO without creating Database connections  In DAO we are writting sql queries , how it is possible without creating and closing database connections
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
datagrid in JSP - JSP-Servlet
datagrid in JSP  sir i want code t create a datagrid view in JSP. I am using oracle 10g. please help me.  Hi Friend, Please visit the following code: http://www.roseindia.net/jsp/data-grid.shtml Hope
Datagrid in JSP - JSP-Servlet
Datagrid in JSP  I Want to display some record in datagrid of JSP page. I am using Apache tomcat server. please help me.  Hi Friend, Please visit the following code: http://www.roseindia.net/jsp/data-grid.shtml
How can I paginate a table which has shown in a div through Ajax in client side without using database
How can I paginate a table which has shown in a div through Ajax in client side without using database   The table is shown by calculation in a PHP script file so The data not store any where so please give me the way to paginate
How retreive data from database without using post method in jsp - JSP-Servlet
How retreive data from database without using post method in jsp  Tell me how?  Hi Friend, If you don't want to use post method then use Ajax.We have provided you a link.In that example, with the use of Ajax, we take
How to get data datagrid ?
How to get data datagrid ?  How to get data datagrid in jsp from arrayList in java? Code in java CategoryDao dao = new CategoryDao(); ArrayList<Categories> lstCategory = new ArrayList<Categories>
ComboBox ItemRenderer in DataGrid
ComboBox ItemRenderer in DataGrid  Hi..... How can I create custom combo box itemtenderer in the flex datagrid? please give me an example...; <mx:DataGrid id="myDG" dataProvider="{myDP
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE  Hello Sir,, Good Morning Actually i have been assigned a task in my college to create a new mobile application and in that i've
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE  Hello Sir,, Good Morning Actually i have been assigned a task in my college to create a new mobile application and in that i've
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE
HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE  Hello Sir,, Good Morning Actually i have been assigned a task in my college to create a new mobile application and in that i've
DataGrid Control in Flex4
DataGrid control in Flex4: The DataGrid control is a MX component. There is no spark component. DataGrid Control is like a Table in html. The DataGrid.... It supports for paging. You can use ArrayList or AvtionScript for creating a DataGrid
DataGrid in Flex
Adobe Flex DataGrid: In Flex, DataGrid is a kind of list which can display... column. Adobe Flex DataGrid provides many features like columns can be resized...;mx:ArrayCollection> and <mx:Object> tags. Adobe Flex Datagrid
JSP Paging Example in Datagrid - JSP-Servlet
JSP Paging Example in Datagrid  Hi, I have tested JSP Paging Example in Datagrid which is available at the following url which i am able to run... to customize its Java file with required fields from the database of my web application
how to make a matrix like datagrid in ide in java pls help
how to make a matrix like datagrid in ide in java pls help  how to make a datagrid mainly matrix in ajava standalone app
without scanner
without scanner  a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following attributes : name , age , salary and note that we need to solve it using array
Flex DataGrid control
DataGrid in Flex:- A DataGrid is a control in flex which is display data... and display via custom renderers. The main features of the DataGrid is that, you can... a DataGrid and what is the procedure to provide data by array collection
How to add a DropDown List in Flex DataGrid
a DropDownList in a DataGrid table. After the user selects one of the items from... a dropDownList in dataGrid. Pls can u tell me how the selected item in my dropdownlist can be recognize and update the value of the cell in the dataGrid and save
How to add a DropDown List in Flex DataGrid
a DropDownList in a DataGrid table. After the user selects one of the items from... a dropDownList in dataGrid. Pls can u tell me how the selected item in my dropdownlist can be recognize and update the value of the cell in the dataGrid and save
JSP Paging Example in Datagrid - JSP-Servlet
========================================= Paging Example Using Datagrid th a:link...-color: cyan; color: #000000;font-weight: bold } .datagrid { border
Advertisements
 

 

 

DMCA.com