aspose file tools*
The moose likes XML and Related Technologies and the fly likes Search fuction in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Search fuction in JSP " Watch "Search fuction in JSP " New topic
Author

Search fuction in JSP

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello, i have to build a search fuction in my website. In main page(JSP) i have a text field and a submit button. When button clicked, user should transfer to goods list (JSP) where all my goods retrieved from store(XML). I have stuck at the point where only goods with name similar to the keyword should be displyed. (ex. If user insert "to" in main page, goods list page should present "Tomatoes" and "Toaster" or if insert "apples" only "Apples")

Any help???
Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Where is the data stored? If it's in a DB, then SQL covers this case (read up on the LIKE operator and the LOWERCASE/UPPERCASE functions). If the data is in files, then using a library like Lucene may help.


Ping & DNS - my free Android networking tools app
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

As i said, i have a xml file and stored all my datas there. Sorry but im a lil bit fresh, what is Lucene library
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
I see, I misinterpreted the mention of XML. You can use one of the XML APIs (maybe SAX or DOM; and possibly XPath) to iterate through all goods and perform some appropriate string operations to do the comparison. Something like nameOfGood.toLowerCase().indexOf(userInput.toLowerCase()) != -1.

As to Lucene, a web search will find its home page (which has extensive documentation) quickly; it's not like that's a common word.
 
Don't get me started about those stupid light bulbs.
 
subject: Search fuction in JSP