0 Replies - 467 Views - Last Post: 07 April 2018 - 01:11 PM

#1 jean2020   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-April 18

filter a result from start date and end date

Posted 07 April 2018 - 01:11 PM

Hello,
I'm trying to filter a result as a list by entering the start date and the end date.

here is listentree.jsp:
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="entity.Entree"%>
<!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=ISO-8859-1">
<title>LISTE DES ENTREES EN STOCK</title>
</head>
<body>
<div>
		<h2>
			<b style="color: blue;"> Liste des entrées en stock</b>
		</h2>
		<hr width="100%;">
	</div>

<form >	
<tr><td>Date entrée début : <input type="date" name="datedebut" required ><td> &nbsp <input type="button" value="Nouvelle Entrée" onclick="document.location.href='NouvelleEntreeCtl';"></br></tr>
</tr><td>Date entrée fin: <input type="date" name="datefin" required></td> &nbsp<td><input type="submit"  value="Filtrer" formaction="ListeEntreesCtl" method="post" ></td></tr>

<table border="1px" width="80%">
    	
    	    <tr>
					<td><b>Date Entrée</b></td>
					<td><b>Reférence</b></td>
					<td><b>Montant total</b></td>
					<td><b>Action</b></td>
				</tr>

<%

ArrayList<Entree> entree1 =(ArrayList<Entree>) request.getAttribute("entrees");
if (entree1!=null){
for(Entree a : entree1) {
%>
				<tr>
					<td><%= a.getDateEntree() %></td>
					<td><%= a.getRefEntree() %></td>
					<td><%= a.getPrixTotalEntree() %></td>
				<td><a
						href="<%=application.getContextPath()%>/Details?id=<%=a.getCodeEntree()%>">
							Détails </a>
				</tr>
								<%
}
}
%>	
				
				
				


</table>
</form>

</body>
</html>



I made a method to retrieve the result:
public List<Entree> RechercherParDate(Date datedebut,Date datefin) {
		return (ArrayList<Entree>)em.createQuery("SELECT a FROM Entree a WHERE dateEntree BETWEEN '"+datedebut+"' AND '"+datefin+"'").getResultList();
		}


here is the code of listentreeCtl.java (the servelet):
package controleur;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import entity.Entree;
import session.ArticleEJBImplLocal;

@WebServlet(name="en",urlPatterns="/ListeEntreesCtl")
public class ListeEntreesCtl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private static final String Date = null;
       
	@EJB
	private ArticleEJBImplLocal imp; 
	
    
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//Date datedebut = null;
		//Date datefin = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
		if ((request.getParameter("datedebut") != null) && (!request.getParameter("datedebut").toString().isEmpty())) {
						
				Date datedebut=null;
				try {
					datedebut = formatter.parse(request.getParameter("datedebut"));
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
if ((request.getParameter("datefin") != null) && (!request.getParameter("datefin").toString().isEmpty())) {
			
				Date datefin = null;
				try {
					datefin = formatter.parse(request.getParameter("datefin"));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
List<Entree> entree1 = imp.RechercherParDate(datedebut, datefin);
request.setAttribute("entrees", entree1);
System.out.println(entree1);
}}
		request.getRequestDispatcher("ListeEntrees.jsp").forward(request, response);	
	}

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

}



after the execution I get nothing result

Is This A Good Question/Topic? 0
  • +

Page 1 of 1