Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly does a JSP runs ? on the client side or server side?

Tags:

java

jsp

servlets

I've read @BalusC's great answer HERE but something is 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 the JSP page called employeePage.jsp on his screen . Doesn't mean that the JSP runs on the client's side ?

So the JSP runs on the client's side , or on the server's side (JSP = Java server page) ?

like image 709
JAN Avatar asked Jan 22 '14 22:01

JAN


5 Answers

The JSP runs on the server-side but it is very common for the JSP to serve, in addition to HTML (and CSS), bits of JavaScript which is then run on the client-side.

A very simple example would be a JSP including some Google Analytics tracker (which is in JavaScript) in the webpage served to your visitors.

Note that I'm not saying that all JavaScript is always run on the client-side: there's also server-side JavaScript. All I'm saying is that JSPs often serves JavaScript and that the JavaScript served by JSPs is run on the client-side.

like image 95
TacticalCoder Avatar answered Oct 24 '22 11:10

TacticalCoder


A JSP is translated into Java servlet before being run, and it processes HTTP requests and generates responses like any servlet. However, JSP technology provides a more convenient way to code a servlet. Translation occurs the first time the application is run. A JSP translator is triggered by the .jsp file name extension in a URL. JSPs are fully interoperable with servlets. You can include output from a servlet or forward the output to a servlet, and a servlet can include output from a JSP or forward output to a JSP.

like image 28
Sunil Singh Bora Avatar answered Oct 24 '22 11:10

Sunil Singh Bora


i understand that i am late in answering this question, but may be it can help someone.

the JSP life cycle involves the following phases:

1) Compilation

2) Initialization

3) Execution

4) Cleanup

JSP Compilation

When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine compiles the page.

The compilation process involves three steps −

1) Parsing the JSP.

2) Turning the JSP into a servlet.

3) Compiling the servlet.

When the JSP is converted into an servlet, it has to be executed at the server side to serve the request.

like image 34
RishikeshD Avatar answered Oct 24 '22 11:10

RishikeshD


JSP is a server-side technology built on Servlets. If you use a container like Tomcat you can see the Servlets generated form the JSP files. In essence the call dispatcher.forward(request, response); is just a call to another Servlet.

like image 29
Romski Avatar answered Oct 24 '22 09:10

Romski


The jSP is running only in server side. it's the java code only the Developer's can easily make code in jsp.

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

like image 32
Mitul Maheshwari Avatar answered Oct 24 '22 10:10

Mitul Maheshwari