DataGrid without DataBase

Ads
 

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 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.

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>

Ads









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
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
Advertisements
datagrid
datagrid   please send datagrid in jsp lot fields including date
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
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
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
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
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
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 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
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
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
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
ModuleNotFoundError: No module named 'DataGrid'
ModuleNotFoundError: No module named 'DataGrid'  Hi, My Python... 'DataGrid' How to remove the ModuleNotFoundError: No module named 'DataGrid... to install padas library. You can install DataGrid python with following
ModuleNotFoundError: No module named 'DataGrid'
ModuleNotFoundError: No module named 'DataGrid'  Hi, My Python... 'DataGrid' How to remove the ModuleNotFoundError: No module named 'DataGrid... to install padas library. You can install DataGrid python with following
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
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 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 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

Ads