Sei sulla pagina 1di 2

The two main uses of jsps are:

1) Using jsp's we can can seperate the presentation logic from business logic ve
ry easily(we can also do the same using the servlets but difficult)
2) Even a web author can easily develop the code ,in the sence a person who does
nt know anything about java can also develop the jsps using the tags
These interfaces defines the three methods for the compiled JSP page. These meth
ods are:
jspInit()
jspDestroy()
_jspService(HttpServletRequest request,HttpServletResponse response)
In the compiled JSP file these methods are present. can define jspInit() and jsp
Destroy() methods, but the _jspService(HttpServletRequest request,HttpServletRes
ponse response) method is generated by the JSP engine.
Steps required for a JSP request:
1. The user goes to a web site made using JSP. The user goes to a JSP page
(ending with .jsp). The web browser makes the request via the Internet.
2. The JSP request gets sent to the Web server.
3. The Web server recognises that the file required is special (.jsp),there
fore passes the JSP file to the JSP Servlet Engine.
4. If the JSP file has been called the first time,the JSP file is parsed,ot
herwise go to step 7.
5. The next step is to generate a special Servlet from the JSP file. All th
e HTML required is converted to println statements.
6. The Servlet source code is compiled into a class.
7. The Servlet is instantiated,calling the init and service methods.
8. HTML from the Servlet output is sent via the Internet.
9. HTML results are displayed on the user's web browser.
The request object in JSP is used to get the values that the client passes to th
e web server during an HTTP request. The request object is used to take the valu
e from the client s web browser and pass it to the server. This is performed using
an HTTP request such as: headers, cookies or arguments. The class or the interf
ace name of the object request is http.httpservletrequest. The object request is
written: Javax.servlet.http.httpservletrequest.
Methods of request Object:
There are numerous methods available for request Object. Some of them are
getCookies()
getHeader(String name)
getHeaderNames()
getAttribute(String name)
getAttributeNames()
getMethod()
getParameter(String name)
getParameterNames()
getParameterValues(String name)
getQueryString()
getRequestURI()
getServletPath()
setAttribute(String,Object)
removeAttribute(String)
The response object denotes the HTTP Response data. The result or the informatio
n of a request is denoted with this object. The response object handles the outp
ut of the client. This contrasts with the request object. The class or the inter
face name of the response object is http.HttpServletResponse. The response objec
t is written: Javax.servlet.http.httpservletresponse. The response object is gen
erally used by cookies. The response object is also used with HTTP Headers.
Methods of response Object: There are numerous methods available for response ob
ject. Some of them are:
setContentType()
addCookie(Cookie cookie)
addHeader(String name, String value)
containsHeader(String name)
setHeader(String name, String value)
sendRedirect(String)
sendError(int status_code)

Potrebbero piacerti anche