Classes of JSP API
JSP API is a set of classes and interfaces that can be used to make a JSP page. These classes and interfaces are contained in the javax servlet.jsp packages. A portion of the classes characterized in the javax. servlet.jsp packages are:
- Error Data
- JSP Writer
- Page Context
The Error Data Class: The error information class characterizes error data for error pages. You have to set the estimation of the page mandate, isErrorPage to be consistent with demonstrating that a page is an error page. The error information class expands the java.lang.Object class. A portion of the strategies characterized in the ErrorData that you can use in a JSP page is:
- getRequestURL(): Returns the mentioned URL through String.
- getServletName(): Returns the name of the servlet conjured through String.
- getStatusCode(): Returns the status code of the blunder as a whole number.
- getThrowable(): Returns the Throwable special case that caused the mistake.
The JspWriter Class: In a JSP page to compose activity and layout information we can utilize JSPWriter class. The understood variable out gives the JSPWriter class object. The JSPWriter class broadens the java.io.Writer class. A portion of the techniques characterize in the JSPWriter class that you can use in a JSP page are:
- clear(): Clears the substance of the cradle. The reasonable() technique tosses an IOException special case if the support is now cleared.
- close(): Closes and flushes the stream.
- flush(): Flushes the cradle stream. The flush() strategy flushes every one of the cradles in a chain of Writers and OutputStream. It tosses java.io.IOException special case on the off chance that you make a call to the compose() or flush() in the wake of shutting the stream.
- getBufferSize(): Return the size of the support utilized by the JSPWriter.
- print(): Prints the estimation of sort boolean, integer, character, long whole number, coasting point, twofold exactness gliding – point number, a variety of character, string, and item. The print() tosses the java.io.IOException exemption if any blunder happens while printing.
- println(): Prints an estimation of sort boolean, whole number, character, long whole number, drifting point, twofold exactness coasting point number, a variety of character, string, and article. The Println() tosses the java.io.IOException exemption if any blunder happens while printing.
The PageContext Class: The setting data is given by the PageContext class when the JSP innovation is utilized in the servlet condition. The PageContext class expands the JSPContext class. A PageContext occasion furnishes access to namespaces related to the JSP page. Some of the strategies characterized in the PageContext class are:
- forward(): Redirects the current servlet demand and servlet reaction to another page. This strategy acknowledges the URL of an objective page as a contention.
- getPage(): Returns the present estimation of the page object.
- getRequest(): Returns the present estimation of the solicitation object. The servlet solicitation is the arrival kind of getRequest().
- getResponse(): Returns the present estimation of the reaction object. The return kind of the getResponse() technique is the servlet reaction.
- getServletConfig(): Returns the ServletConfig of the present page.
- getServletContext(): Returns the ServletContext of the present page.
- getSession(): The arrival kind of getSession() is HttpSession. It will restore the current PageContext.
- include(): Processes the current servlet demand and the reaction determined in the URL. The incorporate() technique accepts two contentions, a URL way and the flush estimation of boolean sort.
Session Tracking in JSP:
- Cookies: A little message field put away on the customers machine. The treat can be impair in the program settings so they are not constantly accessible.
- URL revamping: Store session data in the URL. Works, when treats are not bolstered yet, can make bookmarking of site pages an issue since they have session explicit data toward the finish of a URL.
- Avoided fields: HTML covered up alter boxes, for example:
<input type = "hidden">
- Session objects: JSP Implicit Object. A session article utilizes a key/esteem mix to store information. To retrieve data from a session:
- The arrival kind of the strategy getValue is Object, so you should typecase to get the required worth. Invalid is returned when there is no such key with the session name.