How can i view search results by using servlet and jsp?
Can you give me an example of a simple view results page (jsp) when using servlet in a search engine?
I have tried to follow this example: Search from Database In Servlet but i can`t understand it well. Also in my case I am not working with DB. Any help?
Re: How can i view search results by using servlet and jsp?
What exactly are you searching? Typically, your search output would iterate over some type out search result, and you would print out each entry. In the case you linked to, the servlet performs the search and sets the search result (a List) as a session attribute. The jsp then iterates over this list to print the output. If you are not searching a database, then change the code of the servlet to search whatever you are searching, and set the results as a session attribute which the jsp then can retrieve.
Re: How can i view search results by using servlet and jsp?
I am searcing inside a file server, my output is path to file. Can you give an example code. My servlet is ok i have trouble only with the viewSearch.jsp. In the servlet i store all the found info inside a variable data of type Data
the class Data:
public class Data extends HashMap<String, Set<File>> {
}
so can you give me an example code of the viewSearch.jsp?
I really have trouble understanding how to construct viewSearch.jsp
Re: How can i view search results by using servlet and jsp?
Any reason why you are extending HashMap as opposed to just using the HashMap directly? A bit beside the point but just curious...
In the servlet you set this as a session attribute (using request.setAttribute)...you can then retrieve this in your jsp file using request.getAttribute
You then iterate over the Map...
Code java:
<%
Iterator<String> it = myMap.keySet().iterator();
out.print("<ul>");
while ( it.next() ){
String key = it.next();
out.print("<li>" + key + "</li>");
}
</ul>
%>
This code will print out each 'key' in an html unordered list.