Where exactly does JSP work? client side or server side?

I read the excellent @BalusC answer HERE , but it’s still not clear to me:

On the one hand, when I write a servlet, I do something like this:

String addressPath = "/WEB-INF/results/employee/employeePage.jsp"; RequestDispatcher dispatcher = request.getRequestDispatcher(addressPath); dispatcher.forward(request, response); 

and then the user sees a JSP page called employeePage.jsp on his screen. Doesn't mean JSP is client side?

So does JSP work on client side or server side (JSP = Java server page)?

+6
source share
5 answers

JSP works on the server side, but for JSP it is very often used, in addition to HTML (and CSS), a bit of JavaScript, which is then run on the client side.

A very simple example is the JSP, which includes some Google Analytics tracker (which is in JavaScript) on a web page accessible to your visitors.

Please note that I am not saying that all JavaScript is always executed on the client side: there is also server-side JavaScript. All I am saying is that JSPs often serve JavaScript and that JavaScript served by JSPs is client-side.

+7
source

The JSP is translated into the Java servlet before starting and processes HTTP requests and generates responses like any servlet. However, JSP technology provides a more convenient way to encode a servlet. Translation takes place the first time the application is launched. The JSP translator is triggered by the .jsp name extension in the URL. JSPs are fully compatible with servlets. You can include servlet output or redirect output to a servlet, and a servlet can include JSP or direct output to JSP.

+4
source

JSP is a servlet-based server technology. If you use a container like Tomcat, you can see the created servlets of the form of JSP files. Essentially, calling dispatcher.forward(request, response); is just a call to another servlet.

+2
source

jSP only works on the server side. this is just java code a developer can easily make code in jsp.

jsp is finally converted only to the java servlet. when we use dispatcher.forward(request, response); , it will just redirect you to this servlet.

+1
source

I understand that I am already answering this question late, but maybe this can help someone.

The JSP life cycle includes the following steps:

1) Compilation

2) Initialization

3) Execution

4) Cleaning

JSP Compilation

When a browser requests a JSP, the JSP engine first checks to see if it needs to compile the page. If the page has never been compiled or if the JSP has been modified since the last compilation, the JSP mechanism compiles the page.

The compilation process involves three steps -

1) JSP parsing.

2) Including JSP in the servlet.

3) Compilation of the servlet.

When the JSP is converted to a servlet, it must be executed by the server to service the request.

+1
source

All Articles