FYI, it is not just executed by browser. You need Web/Application Server
inorder to do that. For example Tomcat server. See the web server role from Oracle.
1. How the JSP code is executed?
The web server recognizes that the HTTP request is for a JSP page and
forwards it to a JSP engine. This is done by using the URL or JSP page
which ends with .jsp instead of .html.
2. Why users are not able to see the JSP code/logic by right clicking the html page and clicking Inspect html elements?
The JSP container moves the scriptlet(<% %>) content into the
_jspService() method which is available to the server during processing of the request. For each client’s request the _jspService()
method gets invoked, hence the code inside it executes for every
request made by client. It will give only the resultant text/string.
3. If JSP belongs to java family, how is it getting executed in browser?
From BalusC response,
On a JSP request, the servlet container will execute the compiled JSP
class and send the generated output (usually just HTML/CSS/JS) through
the webserver over network to the client side, which in turn displays
it in the web browser.