View RSS Feed

JSP

Java Server Pages (JSP) tutorials and examples.

  1. What are the Major Servlets Tasks

    by
    JSP
    , 07-07-2012 at 08:31 PM
    Following are the major servlets tasks:

    • The Servlet major task is to read client data that is explicitly sent. It may include:
    o Data sent by a web page in form of HTML form
    o Data sent by an applet
    o Data sent by some HTTP client

    • The Servlet major task is to read client data that is implicitly sent. It may include:
    o Media types
    o Cookies
    o Different compression

    • The servlet is responsible for data processing ...
    Categories
    Tutorial
  2. Exception Handling in JSP

    by
    JSP
    , 07-07-2012 at 08:30 PM
    There is always a probability of programming errors in the code while a programmer is coding a JSP page. Following are the major types of errors which may arise in a JSP code:

    Checked Exceptions: The checked exception is an unforeseen error by the programmer of JSP code or it is a user error in the code. For example, you are opening a file which may not exisit or may have some issue will raise an exception. At the compile time, these checked exceptions cannot be ignored.
    ...
  3. Hits Counter in a JSP Page

    by
    JSP
    , 07-07-2012 at 08:29 PM
    You have a website developed in JSP with different pages. The hit counter will help you the total number of users visit your any JSP page. In most cases, the hit counter is attached with “index.jsp” page. It is the main login page and most users will first visit this page before navigating to any other page on your application or website.

    The following methods are used to implement hit counter. These methods are attached with you “Application” object.

    • setAttribute() ...
    Tags: hits counter Add / Edit Tags
    Categories
    Tutorial
  4. Session Tracking in a JSP Page

    by
    JSP
    , 07-07-2012 at 08:12 PM
    JSP communicates with the clients using stateless HTTP protocol. For each new request, following operations are performed:

    • A new connection is opened with web server.
    • Server does not record client information.

    In this topic, we will focus on the different ways of handling and maintaining session information. Following are the 3 main ways for session maintaining.

    Cookies: A cookies also known as session ID is assigned to a web client by the ...
    Categories
    Tutorial
  5. Form Processing in JSP

    by
    JSP
    , 07-07-2012 at 08:10 PM
    In a JSP progam, a programmer may have handled situations in which he sends information from browser to server and finally this information is communicated to backend business logic. Following two methods are used by the web browsers to send form data and information to web server.

    GET Method: The encoded information is sent from browser to the server using this GET method. The information and page URL is separated using the “?” character. Following is an example of GET method information ...
    Categories
    Tutorial
  6. Expressions in JSP

    by
    JSP
    , 07-07-2012 at 08:09 PM
    The expression elements are supported by the JSP Page which:

    • Are based on scripting language
    • These expressions are evaluated.
    • These expressions are coverted to a String format
    • These are replaced with the expression elements in the JSP Page.

    The expression elements in a JSP page are finally converted to a string so you can use it anywhere in your JSP Page. These expression elements must be valid and follow the Java Language. There is only ...
    Categories
    Tutorial
  7. How a JSP Page is processed?

    by
    JSP
    , 07-07-2012 at 08:07 PM
    In this topic, we will dicuss how a JSP Pages is created and processed by a web server. Following steps will explain it in more detail.

    • An HTTP request is sent to the web server by your JSP Page.
    • The web server is responsible for receiving this JSP Page request and it will determine that it’s a JSP request so it will call the JSP engine. This process is done for the pages that have a .jsp extension.
    • The requested JSP page will be loaded from the disk and the JSP ...
    Categories
    Tutorial
  8. What are the Advantages of JSP

    by
    JSP
    , 07-07-2012 at 08:05 PM
    JSP offers the following advantages as compared to using other technologies in the market.

    JSP vs Active Server Pages: The major benefit offered by the JSP as compared to Active Server Pages is that it uses Java for expression writing which is more helpful, powerful and easy to use. Where as in Active Server Pages, you will need to use Visual Basic or any other Microsoft language. The second benefit offered by the JSP is that you can port it to any other operating system.
    ...
    Categories
    Tutorial
  9. Why we need to Use JSP instead of CGI

    by
    JSP
    , 07-07-2012 at 08:03 PM
    Java Server Pages and Common Gateway Interface (CGI) usually provide the same program functionality. But there are few advantages or features only offered by the Java Server Pages.

    • JSP provided support to use and embed expressions and dynamic elements in HTML page. Where as in CGI, a separate CGI file is used for the same purpose. Thus Java Server Pages provides better performance as compared to CGI.
    • A JSP page is compiled by the web server before it is processed or invoked. ...
    Categories
    Tutorial
  10. JavaServer Pages Introduction

    by
    JSP
    , 07-07-2012 at 07:56 PM
    Java Server Pages is a well known technology for web based application development. It supports:

    • Dynamic content handling
    • Insertion of Java code as expression element in HTML tags.
    • Use of special JSP tags

    Most of the JSP tags start with “<%” and these tags ends with “%>”.

    Java Server Pages are compiled to Servlets and are a specific type of servelts however it offers more benefits over the traditional servlets. Also Java Server ...
    Categories
    Tutorial
  11. Cooperating Tags in JSP

    by
    JSP
    , 07-07-2012 at 07:55 PM
    Java Server Pages provides support for two types of object sharing. This object sharing is achieved using cooperating tags.

    • In first approach, an object is given a name and page context is used to store this object. The page context is implicit object that can be accessed by tag handlers and JSP pages. The following command is used to access a shared object that has been given a name.
    Java Code:
    pageContext.getAttribute( name, scope );
    • In second approach of ...
  12. Tag Handlers in JSP

    by
    JSP
    , 07-07-2012 at 07:54 PM
    The Java Server Pages container invokes the tag handler object in order to evaluate custom tags that are referened by other tags while JSP page is being executed. The Java Server Pages implementation class calls the tag handler methods at different phases of tag evaluation.

    The Java Server Pages invokes the doStartTag method handler so that an appropriate method handler is initialized when ever a start tag is encountered of a custom tag. The Java Server Pages invokes the doEndTag ...
    Categories
    Tutorial
  13. JSP Include

    by
    JSP
    , 07-07-2012 at 06:14 PM
    The <jsp:include> makes it possible for you to include the dynamic or static file in JSP file. To include dynamic or static file would be generating the different results. In case file is static the contents would be included in “Calling JSP” files. And if files are dynamic then act is done at the request and result is sent which would be included into JSP pages. When finishing of include action is fone then processing is continued of the remainder by JSP container.

    Attributes ...
    Tags: jsp include Add / Edit Tags
    Categories
    JSP Include
  14. Scope of the JSP objects

    by
    JSP
    , 07-07-2012 at 06:07 PM
    It is determined by the JSP object scope that object could be used at some specific place of an application or not. Four scopes are present for the JSP object, as following:

    application - Object that has this kind of scope is present with all kind of JSP pages that belong to similar web applications.
    session - Object that has this kind of scope would be there for all kind of JSP pages which belong to the similar session where such object got instantiated.
    request - Object ...
    Categories
    Scope
  15. What is JSP Actions?

    by
    JSP
    , 07-07-2012 at 06:05 PM
    Certain built in kind of functionalities are provided by the servlet container so that the application development could be eased. These functions are used by the programmers in JSP applications. Programmers are abled by the JSP action tags to utilized such functions. XML tags could be used in pages of JSP.
    Here is the list of JSP Actions:

    jsp:include
    The jsp:include where action work to be like a subroutine. Requests as well as responses are temporarily passed by the ...
    Categories
    Tutorial
  16. Jsp architecture

    by
    JSP
    , 07-07-2012 at 06:04 PM
    JSP pages are considered to be the higher leveled servlet extension which make developers able to do embedding of the java code into HTML. Finally, JSP files get compiled in servlet by the help of servlet engine. Compiled servlet serve the requests when is used by the engine.

    javax.servlet.jsp package has 2 interfaces:

    • HttpJspPage
    • JSPPage

    These interfaces has 3 methods for JSP page. They are:

    • jspInit()
    • _jspService(HttpServletRequest ...
    Categories
    Tutorial
  17. JSP and Servlets

    by
    JSP
    , 07-07-2012 at 06:02 PM
    In case you have dealed with Java Servlets then you would be knowing that they make it possible for you to make the web pages which are dynamically generated which contain data from java objects “server side”. Servlet approach for generation of the web pages is to do embedding of the presentation code and HTML tags in Java class. This shows that alteration in presentation code would be requiring recompilation and modification of the source file of servlet. As web authors of HTML design are not always ...
    Categories
    Tutorial
  18. TagExtraInfo Class

    by
    JSP
    , 01-01-2012 at 07:26 PM
    A TagExtraInfo class gives out certain extra data or information regarding the attributes of tags to the JSP container, at translation time.

    • Returns information or data regarding the scripting variables which is made available by the tag to the remaining JSP page for use. Following method is used.

    Java Code:
    VariableInfo[] getVariableInfo(TagData td)
    
    <html>
    <myTag:addObjectsToArray name=”myArray” />
    <myTag:displayArray name=”myArray”
    ...

    Updated 01-14-2012 at 07:08 PM by JSP

    Categories
    Uncategorized
  19. JSP URL Mapping

    by
    JSP
    , 01-01-2012 at 07:23 PM
    Given in the figure below JSP resources reside under subdirectories or directly there in the document root that are accessible directly to users via URL. In order to protect the web resources, behind WEB-INF directory hide the JSP files that provide protection to JSP files, Java Script files, image files, css files (cascading style sheets), pdf files, html files etc, from the direct access. To servlet, a request shall be made as it is responsible for the authorization as well as authentication of ...

    Updated 01-15-2012 at 08:41 AM by JSP

    Categories
    URL Mapping
  20. Is JSP variable declaration thread safe?

    by
    JSP
    , 01-01-2012 at 07:20 PM
    No, in JSP the variable declaration is not at all thread safe as the declared variables are ended up as instance variable in generated servlet not in body of _jspservice() method.

    The given declaration is not considered to be thread safe: as they are declarations and are evaluated only one time when page gets loaded.

    <%!int a=5;%>

    The given declaration is considered thread safe: as in the scriplets the variables that have been declared are not shared ...
  21. Hidden and Output Comments

    by
    JSP
    , 01-01-2012 at 07:00 PM
    An output comment is sent to the client where it becomes viewable in the source of browser.

    <!-- This is a comment which is sent to client -->

    JSP page is documented by hidden comment however it is not sent to client. Hidden comment is ignored by the JSP engine and no code is processed in tags of the hidden comments.

    <%-- This comment will not be visible to client --%>

    Updated 01-15-2012 at 08:43 AM by JSP

    Categories
    Comment
  22. Implicit Objects

    by
    JSP
    , 01-01-2012 at 06:56 PM
    Implicit objects are those objects which are present to be used in the JSP documents without declaration. JSP engine parses such objects and are inserted to the generate servlet. Following are the servlet objects:

    Name:  18.JPG
Views: 1022
Size:  33.4 KB
    Implicit Objects
  23. Main elements of a JSP

    by
    JSP
    , 01-01-2012 at 06:54 PM
    In a JSP page, two types of data are present.

    • Static part (ie CSS, HTML etc), that is copied to the response directly by the JSP Engine.
    • Dynamic part that consists of anything which can be compiled and translated by the JSP Engine.

    Dynamic elements consist of 3 elements.

    • Scripting Elements: A JSP element which gives out the embedded Java statements. Three kinds of scripting elements are present.

    o Declaration Element: is
    ...

    Updated 01-14-2012 at 07:04 PM by JSP

    Categories
    Tutorial
  24. Life cycle methods of a JSP

    by
    JSP
    , 01-01-2012 at 06:47 PM
    • Pre-translated: Before the JSP file is compiled or translated, into the Servlet.
    • Translated: The JSP file is being compiled & translated as a Servlet.
    • Initialized: Before handling requests of service method, the container calls the jspInit() to do the initialization of the Servlet. Called just one time per Servlet instance.
    • Servicing: client requests are served. For each request, container calls it.
    • Out of service: The Servlet instances are out of their services. The container calls
    ...
  25. What is JSP?

    by
    JSP
    , 01-01-2012 at 06:45 PM
    Java Servlet technology’s extension is Java ServerPages. JSP is used as presentation layer to combine the Java code and HTML. Java Servlet technology generates HTML along with out.println(“<html>….. </html>”) statements (out is PrintWriter). Embedding HTML code to the escape characters is a process which is hardly maintained and is cumbersome. A level of abstraction is provided by the JSP technology in order to enable a developer to use the action elements and custom tags. This makes ...