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 :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Blackpanther0001
  • 258
  • 1
  • 3
  • 14

1 Answers1

1

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

  • An example would be [Example servlet filter that catches and blocks ips that request suspicious url](https://stackoverflow.com/questions/18394628/example-servlet-filter-that-catches-and-blocks-ips-that-request-suspicious-url) – JGlass Jan 26 '18 at 19:24
  • I tried with this annotation for my Servlet and its doing the job: @WebServlet("/*") public class ServletT extends HttpServlet {..} – Blackpanther0001 Jan 26 '18 at 22:45
  • that's an actual servlet. which will work, too. but typically people use servlet filters for such things. but what you did works, obviously. –  Jan 27 '18 at 07:08