1

I am in the following situation:

Client makes some request -> Servlet gets all requests -> based on requested url (example: https://bla.com/classic) it fetches products from database -> invokes a jsp page and passes products array as parameter -> jsp page rendes HTML to client

How can this be achieved ? More specific question:

1.How to catch all client requests with a servlet and get the requested url ?

2.How to call jsp from servlet and pass parameters to it, so it can render the correct HTML ?

I am trying to build an MVC-like application. In this case my servlet is the controller (gets all requests), a database-helper-class is my model (gets products from db) and the jsp file is my view (renders html).

Thanks in advance :)

1
  • You need something called as a filter. Commented Jan 26, 2018 at 17:03

1 Answer 1

1

You need a ServletFilter and a properly configured web.xml for the paths.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried with this annotation for my Servlet and its doing the job: @WebServlet("/*") public class ServletT extends HttpServlet {..}
that's an actual servlet. which will work, too. but typically people use servlet filters for such things. but what you did works, obviously.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.