import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class NameSearch extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String token = req.getParameter("search");
PersistenceManager pm=PMF.get().getPersistenceManager();
String query= "select from " + Student.class.getName();
List
ArrayList results = new ArrayList();
for (Student a:students)
{
// Checking whether token appears in the name whether lower or upper
if (a!=null && token!=null)
if(a.getName().toLowerCase().indexOf(token.toLowerCase()) != -1)
{
// Adding the reference to the object into the ArrayList
System.out.println(a.getName());
results.add(a);
}
}
req.setAttribute("result", results);
//Sending the results data via RequestDispatcher to your JSP Page.
RequestDispatcher r=req.getRequestDispatcher("SearchAS.jsp");
try
{
r.forward(req, resp);
} catch (ServletException e)
{
e.printStackTrace();
}
}
}
No comments:
Post a Comment