This is a general question about best practices. I have a JSP with a search form on it. The form submits to a servlet, which queries the database and returns search results. I would like to display the results below the form, and have the form still populated with the original search terms. I know I could do this with an Ajax call, but I want to know if it is a good idea for the servlet to forward the results to the same JSP that made the request, so the JSP can display the form, and then display the results below it. Is there a better design? Thank you for your help.
Share
There is nothing wrong with this design. You just have to remember that JSP is used in two scenarios: on first run, when you shouldn’t display anything extra and on search result, when extra list should be rendered.
If you want slightly cleaner approach, extract your common layout and form into a separate
JSP file, that will never be accessed directly. Then have two JSPs including the extracted one. First doing only this and second – also rendering search result below included JSP.