Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anything that can be implemented with Servlets and not with JSPs or vice versa

We know that JSPs gets converted to Servlets, Servlets are for the Buisines logic and JSPs for the view etc... But theoretically, you can do most of the things you do with JSP with a servlets. Same thing the other way round.

But Is there anything that you can implement with Servlets and not with JSPs or vice versa?

I got this question some time back in an interview, but did not find any answer after lots of googling.

like image 379
ManuPK Avatar asked Nov 14 '11 13:11

ManuPK


1 Answers

But Is there anything that you can implement with Servlets and not with JSPs or vice versa?

Technically, there's nothing which can be implemented by only either of them.

Functionally, there's a huge difference with regard to maintainability when you follow the MVC design pattern and implement the controller part in the servlet and the view part in the JSP. The Servlet API offers a much clearer abstraction to hook on specific HTTP methods and control the request/response before any bit is written to the response. JSP in turn is part of the response which can make some tasks harder to implement, such as changing the response in case of an exception.

See also:

  • Our JSP wiki page
  • Our Servlets wiki page
  • How to avoid Java code in JSP files?
like image 182
BalusC Avatar answered Sep 25 '22 18:09

BalusC