0

I am trying to design a jsp page where by a user enters the name of a field ( say father's name) and enters a value. I want to search the database and return all those possible student name whose father's name matches to the one entered by the user.


Now, the problem is this that i want to return all the names of the student in a row wise manner ( pretty much like how google returns a set of values when we search for anything ) with a little description. I also want to display the result in the same page in which the user entered the values.


How should i use servlets to accomplish this. Just a little outlook of the code would be helpful ??

Chitransh Saurabh
  • 377
  • 6
  • 12
  • 23

1 Answers1

1

I am trying to design a jsp page

Here you need to have a simple page which can check GET request parameter such as:

http://www.example.com/?q=a+father+name&page=2&so-on-as-per-your-need

Now you will need two servlets:

  1. First, search servlet that contains search options, like a field as you said.
  2. Second, the result servlet, having capacity to search an display result

I want to search the database

Keep your DAO methods in separate class just to keep your business logic away from servlet or jsp.

I consider that you can search the database for your matching values, and as you said you want some description also you need to have that stored in database.

I also want to display the result in the same page

You have include and forward options with JSP, you just have to take any of these options on the basis of parameter q, if it is null than forward/include the request on search servlet. If q has any value than forward/include the request to result servlet.

In this way you have only one view and two controllers for this.

Hope it helps.

Further Readings that may help you:

Community
  • 1
  • 1
Asif
  • 4,980
  • 8
  • 38
  • 53