Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How can i view search results by using servlet and jsp?

  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  3. #3
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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...
    <%
     
    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.

Similar Threads

  1. What are the requirements to develop Servlet Application?
    By yousef atya in forum Java Servlet
    Replies: 2
    Last Post: July 28th, 2011, 06:20 PM
  2. Showing database results
    By randyrr in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 27th, 2010, 11:26 PM
  3. Searching and printing string results from an Arraylist. Having difficulty.
    By Espressoul in forum Loops & Control Statements
    Replies: 1
    Last Post: February 25th, 2010, 08:32 PM
  4. How to print results to screen
    By NinjaLink in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2010, 01:46 PM
  5. Football Results
    By RSYR in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2009, 07:24 PM