Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:45:19+00:00 2026-05-31T15:45:19+00:00

I have this Code… ifsDAO.java package source; import java.sql.*; import java.sql.SQLException; import java.util.*; public

  • 0

I have this Code…

ifsDAO.java

package source;

import java.sql.*;
import java.sql.SQLException;
import java.util.*;


public class ifsDAO {

private Database database;

public ifsDAO(Database database) {
this.database = database;

}

public List<ifsBean> list() throws SQLException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
List<ifsBean> ifs_array = new ArrayList<ifsBean>();



try {

connection = database.getConnection();
statement = connection.prepareStatement("select * from emp_details");
resultSet = statement.executeQuery();
while (resultSet.next()) {
ifsBean arraylist = new ifsBean();
arraylist.setFname(resultSet.getString("fname"));
arraylist.setSname(resultSet.getString("sname"));
arraylist.setTown(resultSet.getString("town"));
ifs_array.add(arraylist);
}
} finally {
if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
}

return ifs_array;
}
}

ifsBean.java

package source;


public class ifsBean {

private String fname;
private String sname;
private String town;

public String getFname() { return fname; }
public String getSname() { return sname; }
public String getTown() { return town; }

public void setFname(String fname) { this.fname = fname; }
public void setSname(String sname) { this.sname = sname; }
public void setTown(String town) { this.town = town; }
}

Database.java

package source;

import java.sql.*;

public class Database {
private String url;
private String username;
private String password;

public Database(String driver, String url, String username, String password) {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Driver class is missing in classpath", e);
}
this.url = url;
this.username = username;
this.password = password;
}

public Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, username, password);
}
}

ifsServlet.java

package source;

import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;


public class ifsServlet extends HttpServlet {

private ifsDAO ifsDAO;


@Override
public void init() throws ServletException {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost/mydb";
String username = "user";
String password = "pass";


Database database = new Database(driver, url, username, password);
this.ifsDAO = new ifsDAO(database);
}


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

try {
List<ifsBean> ifs_array = ifsDAO.list();

request.setAttribute("ifs_array", ifs_array);
request.getRequestDispatcher("ifslist.jsp").forward(request, response);
} catch (SQLException e) {
throw new ServletException("Cannot retrieve areas", e);
}
}
}

ifslist.java

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello</h1>
<table>
<c:forEach items="${ifs_array}" var="array">
<tr>
<td>${array.fname}</td>
<td>${array.sname}</td>
<td>${array.town}</td>

</tr>
</c:forEach>



</table>

</body>
</html>

I can display all the data and it works very well

however how can I filter the results here using a filter or a link and parameters…

Example: http://www.example.com?id=parameter

sorry im very new to this.. and learning…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:45:20+00:00Added an answer on May 31, 2026 at 3:45 pm

    Your question is a bit broad, but here are few tips:

    • I assume you know how to perform another GET request with extra ?name=parameter to the same servlet.

    • In your servlet’s doGet() method you need to obtain the value of name parameter:

      String name = request.getParameter("name");
      

      this will return null if name= parameter was not present

    • Pass your name to DAO layer. You will need an extra parameter to list() method:

      List<ifsBean> ifs_array = ifsDAO.list(name);
      
    • In your DAO you need to take advantage of this parameter:

      connection.prepareStatement("select * from emp_details WHERE fname = ?");
      

      Then you need to pass your name to the query, see Using Prepared Statements for details.

    That’s it! Your code uses very low-level structures, but looks fine besides that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in a single file : public class genIntro { public
I have this code but it doesn't work! public class Trial { public static
I have this code in my forms.py : from django import forms from formfieldset.forms
I have this code private void writeReport(IReport report, string reportName) { string reportString =
I have this code: <div class = content-dir-item> <p>Text input</p> <img src=./images/email.png class =
I have this code which gets info from an other class but I have
I have this code for converting a byte[] to float[] . public float[] ConvertByteToFloat(byte[]
I have this code, that draws an image. private void timer1_Tick(object sender, EventArgs e)
have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args)
have this code: template<typename T, template<typename, typename> class OuterCont, template<typename, typename> class InnerCont, class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.