Results 1 to 3 of 3
  1. #1
    Payatola2287 is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default Listing problems

    Im having a problem on listing the result of a query.
    im kinda out of ideas. in my sample website, i want to pass the values from the servlet to the jsp file. i used ArrayList to display the data. i successfully display the data. but now i want it to be in a table so table it would be organized. i want to display one column from the database in one <td> tag. here's my codes

    <%@ page import = "java.util.* , db.Show" language="java" contentType="text/html; charset=ISO-8859-1"
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    Show li = new Show();
    ArrayList al = li.getList();
    Iterator i = al.iterator();


    <%= %>



    Java Code:
    package db;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     * Servlet implementation class List
    public class Show extends HttpServlet {
        public Show() {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
        public ArrayList<String> getList(){
            String driver = "org.sqlite.JDBC";
            String url = "jdbc:sqlite:D:\\Java\\workspace\\Softdev\\SampleWebProj\\WebContent\\Customer.db";
            String sql = "";
            PreparedStatement ps = null;
            ResultSet r = null;
            Connection con = null;
            ArrayList<String> l = new ArrayList<String>();
                con = DriverManager.getConnection(url);
                sql = "SELECT * FROM Account";
                ps = con.prepareStatement(sql);
                r = ps.executeQuery();
                    String username = r.getString("username");
                    String password = r.getString("password");
            }catch(Exception s){
            return l;
    Last edited by Eranga; 03-04-2012 at 09:14 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

    Default Re: Listing problems

    Please use code tags when you are posting code segments in the forum. Unformatted codes are really hard to read.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Listing problems

    First, that servlet is seriously wrong...especially the instantiation of it in the JSP.

    The servlet is constructed by your server.
    It is called (doGet or doPost) when the client makes a request that maps to that servlet (in the web.xml).
    You would then do your business logic (generally not in the servlet, but in a layer that is called by the servlet, in your case a DataAccessObject possibly, but we'll skip that bit) and place the List into the request (setAttribute). It would then forward to your JSP page.
    The JSP would retrieve the List from the request (getAttribute) and display it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. listing files at the FTP
    By oulutas in forum New To Java
    Replies: 6
    Last Post: 10-10-2010, 12:30 PM
  2. Listing Installed DSA
    By anoopasta in forum XML
    Replies: 1
    Last Post: 05-06-2010, 05:10 PM
  3. Listing the alphabet (beginner)
    By SuperOnion in forum New To Java
    Replies: 3
    Last Post: 12-22-2008, 04:23 AM
  4. Listing Logical Drives
    By Juggler in forum New To Java
    Replies: 3
    Last Post: 08-10-2008, 08:08 AM
  5. Listing all available Locales
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 05:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts