Monday, August 26, 2019

Caching in Asp.net for B.C.A., M.C.A. and all IT Students


--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD) - IT
E-Mail : rupareleducation@gmail.com
Contact No : 7600044051

::  Caching Application Page and Data :: 

What is Caching?

·        Caching is a technique of storing frequently used data and information in memory, so that, when the same data and information is needed next time, it could be directly retrieved from the memory instead of being generated by the application.
·        Caching is extremely important for performance boosting in ASP.NET, as the pages and controls are dynamically generated here.
·        It is especially important for data related transactions, as these are expensive in terms of response time.
·        Caching places frequently used data in quickly accessed media such as the random access memory of the computer.
·        The ASP.NET runtime includes a key-value map of CLR objects called cache.
·        This resides with the application and is available via the HttpContext and System.Web.UI.Page.

 Page Output Cache

·        A typical kind of caching for server applications is output caching.
·        PageOutput caching enables you to store rendered HTML.
·        The stored HTML is served in response to subsequent requests for the same page.
·        You can use output caching to cache a whole Web page or just the output of an ASP.NET control.
·        PageOutput caching is extensible.
·        You can use a custom output cache provider that can store data on any data storage device.
·        The page output cache stores the contents of a processed ASP.NET page in memory.
 Partial Page Cache
·        Partial-page caching persists specified portions of a page and lets other portions of the page be created dynamically.
·        Partial-page caching can work in two ways: control caching and post-cache substitution.
·         This can be achieved by partial or fragment caching.
·        In this caching, specific parts of a web page are cached, and the remaining content of the web page is refreshed each time the page is requested.

Absolute Expiration 

·        Absolute expiration means that your data will be removed from cache after fixed amount of time either it is accessed or not.
·        Generally we use it when we are displaying data which is changing but we can afford to display outdated data in our pages. 
·        This will be absolute expiration whether cache will be used or not It will expire the cache.
·        This type of expiration used to cache data which are not frequently changing.

Sliding Expiration

·        Sliding expiration means It will expire cache after time period at the time of activating cache if any request is not made during this time period.
·        This type of expiration is useful when there are so many data to cache.
·        So It will put those items in the cache which are frequently used in the application.
·        So it will not going to use unnecessary memory.

Data Caching:

·        The main aspect of data caching is caching the data source controls.
·        We have already discussed that the data source controls represent data in a data source, like a database or an XML file.
·        These controls derive from the abstract class DataSourceControl
·        This is the most flexible type of caching but requires some code to implement.
·        The basic principle is that you add items that are expensive to create to a special built-in collection object (called cache), which is globally available.
·        Unlike the application object it is thread-safe i.e. you need not lock or unlock the collection before adding or removing an item.
·        Cache items are removed automatically when expired. Items in the cache support dependencies.
·        You can add an item to the cache by simply by assigning a new key name. Like: Cache[“key”] = item;


:: Best of Luck :: 

Please share and comment it... Thank you

https://myshopprime.com/uday.shah3/shop

Wednesday, August 21, 2019

Advanced Java Programming (J2EE) Using JSP for B.C.A., M.C.A. and all IT Students


--------------------------------------------------------------------------------------------------------------------------
Developed By : Uday Shah (HOD - IT)
E-Mail : rupareleducation@gmail.com
Contact No : 7600044051

Advanced Java Programming (J2EE)

JSP Introduction

·        It stands for Java Server Pages.
·        It is a server side technology.
·        It is used for creating web application.
·        It is used to create dynamic web content.
·        JSP tags are used to insert JAVA code into HTML pages.
·        It is an advanced version of Servlet Technology.
·        It is a Web based technology helps us to create dynamic and platform independent web pages.
·        They are easy to maintain.
·        No recompilation or redeployment is required.
·        JSP has access to entire API of JAVA.
·        JSP are extended version of Servlet.
·        Using JSP, one can easily separate Presentation and Business logic.
·        JSP pages are converted into Servlet by the Web Container. 
·        JSP pages can be directly accessed, and web.xml mapping is not required like in servlets.
·        JSP is built on Java technology, so it is platform independent.

Difference between JSP V/s Servlet
JSP
SERVLET
JSP is a html based code
Servlet is a java based code.
It is easy to code as it is java in html.
Writing code for servlet is harder than JSP as it is html in java.
JSP is the view in MVC Architecture for showing output.
Servlet plays a controller role in MVC Architecture.
JSP is slower than Servlet.
Servlet is faster than JSP.
JSP only accept http requests.
Servlet can accept all protocol requests.
In JSP, we cannot override its service() method.
In Servlet, we can override the service() method.

JSP Architecture
·        The web server needs a JSP engine, i.e, a container to process JSP pages.
·        The JSP container is responsible for intercepting requests for JSP pages.
·        A JSP container works with the Web server to provide the runtime environment and other services a JSP needs.
·        Java Server Pages are part of a 3-tier architecture.
·        JSP contains both Java and HTML in the same file.
·        JSP can be easily managed because business logic is separated from presentation logic.
·        The following diagram shows the JSP architecture.


·        According to above architecture.
·        As with a normal page, your browser sends an HTTP request to the web server.
·        The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine.
·        This is done by using the URL or JSP page which ends with .jsp instead of .html.
·        The JSP engine loads the JSP page from disk and converts it into a servlet content.
·        This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code.
·        The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine.
·        And finally, the web browser handles the dynamically-generated HTML page inside the HTTP response exactly like static page

JSP Life Cycle
·        JSP Life Cycle is like the servlet, each JAVA EE part will have its own particular life cycle.
·        A JSP life cycle can be portrayed as the entire system from its introduction till the decimation which resembles a servlet life cycle with an additional step which is required to arrange a JSP into the servlet.
·        A JSP life cycle is defined as the process from its creation till the destruction.
·        This is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
·        Following steps are involved in JSP life cycle:
·        Translation of JSP page to Servlet
·        Compilation of JSP page
·        Class loading
·        Instantiation means Object of the generated Servlet is created.
·        Initialization means jspInit() method is invoked by the container.
·        Request processing jspService() is invoked by the container.
·        JSP Cleanup jspDestroy() method is invoked by the container.



JSP Elements
·        JSP Scripting element are written inside <% %> tags.
·        These code inside <% %> tags are processed by the JSP engine during translation of the JSP page.
·        Any other text in the JSP page is considered as HTML code or plain text.
·        There are five different types of scripting elements

Scripting Element
Example
Comment
·        JSP Comment is used when you are creating a JSP page and want to put in comments about what you are doing.
·        JSP comments are only seen in the JSP page.
<%-- comment --%>
Directive
Directive Tag gives special instruction to Web Container at the time of page translation. Directive tags are of three types: page, include and taglib.
<%@ page ... %> : defines page dependent properties such as language, session, errorPage etc.
<%@ include ... %> : defines file to be included.
<%@ taglib ... %> : declares tag library used in the page
<%@ directive %>
Declaration
  • A declaration tag is a piece of Java code for declaring variables, methods and classes.
  • If we declare a variable or method inside declaration tag it means that the declaration is made inside the servlet class but outside the service method.
<%! declarations %>
Scriptlet
·        Scriptlet Tag allows you to write java code inside JSP page. 
  • A Scriptlet contains java code that is executed every time JSP is invoked.
<% scriplets %>
Expression
  • Expression tag evaluates the expression placed in it.
  • It accesses the data stored in stored application.
  • It allows create expressions like arithmetic and logical.
  • It produces scriptless JSP page.
<%= expression %>
JSP Action Tags
  • The action tags are used to control the flow between pages and to use Java Bean.
  • The Jsp action tags are given below
  • jsp:param : sets the parameter value. It is used in forward and include mostly.
  • jsp:include : includes another resource.
  • jsp:forward: forwards the request and response to another resource.
  • jsp:plugin: embeds another components such as applet.




<jsp:include page="printdate.jsp" />
<jsp:forward page="printdate.jsp" />

JSP Implicit Objects
  • These Objects are the Java objects that the JSP Container makes available to the developers in each page and the developer can call them directly without being explicitly declared.
  • JSP Implicit Objects are also called pre-defined variables.
  • There are 9 jsp implicit objects. These objects are created by the web container that is available to all the jsp pages.
No.
Description
1
Request: This is the HttpServletRequest object associated with the request.
2
Response: This is the HttpServletResponse object associated with the response to the client.
3
Out: This is the PrintWriter object used to send output to the client.
4
Session: This is the HttpSession object associated with the request.
5
Application: This is the ServletContext object associated with the application context.
6
Config: This is the ServletConfig object associated with the page.
7
PageContext: This encapsulates use of server-specific features like higher performance JspWriters.
8
Page:  This is simply a synonym for this, and is used to call the methods defined by the translated servlet class.
9
Exception: The Exception object allows the exception data to be accessed by designated JSP.

JSP Scope
·         The availability of a JSP object for use from a particular place of the application is defined as the scope of that JSP object.
·         Every object created in a JSP page will have a scope.
·         Object scope in JSP is segregated into four parts and they are page, request, session and application.
Page 
·         Page scope means the JSP object can be accessed only from within the same page where it was created.
·         The default scope for JSP objects created using <jsp:useBean> tag is page.
·         JSP implicit objects out, exception, response, pageContext, config and page have page scope.
Request
  • A JSP object created using the request scope can be accessed from any pages that serve that request.
  • More than one page can serve a single request.
  • The JSP object will be bound to the request object.
  • Implicit object request has the request scope.
Session
·         Session scope means, the JSP object is accessible from pages that belong to the same session from where it was created.
·         The JSP object that is created using the session scope is bound to the session object.
·         Implicit object session has the session scope.
Application
  • A JSP object created using the application scope can be accessed from any pages across the application.
  • The JSP object is bound to the application object.
  • Implicit object application has the application scope.
Including and Forwarding from JSP Pages
  • These actions use constructs in XML syntax to control the behavior of the servlet engine.
  • You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.
  • Following is syntax
<jsp:action_name attribute = "value" />
  • According to above there are two attributes that are common to all Action elements.
  • Thai is id attribute and the scope attribute.
Id attribute
  • The id attribute uniquely identifies the Action element, and allows the action to be referenced inside the JSP page.
  • If the Action creates an instance of an object, the id value can be used to reference it through the implicit object.
Scope attribute
  • This attribute identifies the lifecycle of the Action element.
  • The id attribute and the scope attribute are directly related, as the scope attribute determines the lifetime of the object associated with the id.
  • The scope attribute has four possible values that is 
·         Page
·         Request
·         Session
·         Application
Jsp : include Action
  • The jsp: include action tag is used to include the content of another resource it may be jsp, html or servlet.
  • The jsp include action tag includes the resource at request time so it is better for dynamic pages because there might be changes in future.
  • The jsp: include tag can be used to include static as well as dynamic pages.
  • Main Advantages of JSP code is  reusability .
  • We can use a page many times such as including header and footer pages in all pages. So it saves a lot of time.
Working with Session & Cookie in JSP
·         Cookies are text files stored on the client computer and they are kept for various information tracking purposes.
·         JSP transparently supports HTTP cookies using underlying servlet technology.
·         There are three steps involved in identifying and returning users
·         Server script sends a set of cookies to the browser. For example, name, age, or identification number, etc.
·         Browser stores this information on the local machine for future use.
·         When the next time the browser sends any request to the web server then it sends those cookies information to the server and server uses that information to identify the user or may be for some other purpose as well.
·         In Session JSP makes use of the servlet provided HttpSession Interface.
·         This interface provides a way to identify a user across.
·         By default, JSPs have session tracking enabled and a new HttpSession object is instantiated for each new client automatically
·         The JSP engine exposes the HttpSession object to the JSP author through the implicit session object.
·         Since session object is already provided to the JSP programmer, the programmer can immediately begin storing and retrieving data from the object without any initialization or getSession ().
Error Handling and Exception Handling with JSP
·         The exception is normally an object that is thrown at runtime.
·         Exception Handling is the process to handle the runtime errors.
·         There may occur exception any time in your web application.
·         So handling exceptions is a safer side for the web developer.
·         In JSP, there are different ways to perform exception handling.

·         Using Error Page
·         JSP gives you an option to specify Error Page for each JSP. Whenever the page throws an exception, the JSP container automatically invokes the error page.
·         To set up an error page, use the <%@ page errorPage = "xxx" %> directive.
·         And for error-handling page includes the directive <%@ page isErrorPage = "true" %>
·         Using JSTL Tags
·         You can make use of JSTL tags to write an error page ShowError.jsp.
·         This page has almost same logic as in the ErrorPage, with better structure and more information
·         In this case, either specifies exception-type or error-code with the location element.
·         If you want to handle all the exception, you will have to specify the java.lang.Exception in the exception-type element.
·         Using Try...Catch Block
·         If you want to handle errors within the same page and want to take some action instead of firing an error page, you can make use of the try....catch block.
·         Exception handling in JSP is same as in java where we manage exceptions using try catch blocks.

:: Best Of Luck :: 

https://myshopprime.com/uday.shah3/shop

Please share and comment it. Thank You...