Define JSP
By Ramakrishna on Oct 16, 2008 in Java Important Notes
The instance variables and methods are initialized when the JSP is first requested. After that, each thread can access those instance variables and methods.
The synchronized keyword prevents two threads from using the method or modifying the instance variable at the same time. This results in a thread-safe JSP.
First, each JSP is translated into a servlet class.
Second, the servlet class is compiled when the first user requests the JSP.
Third, one instance of the servlet class is instantiated when the first user requests the JSP.
Fourth, each user is treated as a thread by the servlet, and each thread gets its own copy of the local variables of the servlet methods.
When you use the Get method to pass parameters to a JSP, the parameters are displayed in the URL. When you use the Post method, they aren’t. Although the Get method transfers data faster than the Post method, you can’t use the Get method to transfer more than 4K of data.
You use a JSP directive known as a page directive to import classes for use in a JSP.
When you use JSP comments, the comments aren’t compiled or executed. In
contrast, HTML comments are compiled and executed, but the browser doesn’t display them.
You use JSP declarations to declare instance variables and methods for a JSP. To code a thread-safe JSP, you must synchronize access to these instance variables and methods.
When a JSP is first requested, the JSP engine translates the page into a servlet and compiles it. Then, one instance of the class is instantiated. For each subsequent request, a new thread is created from this single instance of the servlet class. This means that each requestor gets its own copy of the local variables, but all requestors share the same instance variables.
Within the doGet method, the first two statements perform tasks that are
common to most servlets that return an HTML document. Here, the first statement sets the content type that will be returned to the browser. In this case, the content type is set so that the servlet returns an HTML document, but it’s possible to return other content types. Then, the second statement returns a PrintWriter object that’s used to return data to the browser later on.
The doPost method calls the doGet method, an HTTP request that uses the Post method will actually execute the doGet method of the servlet.

1 Trackback(s)