Books Related to Java, Core Java, Jquery, Web Services, SCJP, Spring, Hibernate and J2ME

Sunday, May 24, 2009

Make Money Online - Online Home Based Job

Hi ,

I have something interesting for you, RupeeMail!

It’s really amazing! You get paid to open & read the contents of RupeeMail. You receive promotional offers & special discounts in RupeeMail.

Interestingly RupeeMails will reach you based on the preference list you opted for.

Create your RupeeMail Account & refer your friends to earn launch referral bonus on every new registration.

Try this... Join Now!

RupeeMail, It pays

Monday, April 27, 2009

Web Server Request

Each request must internally specify which method of returning data to the web server is being used. the three most commonly used methods, specified within the request are:

2. GET

The HEAD method is simply retrieves information about a document and not the document itself. It is very identical to the GET method except that the web server returns no user data.
The GET and POST methods are the ones that are use to issue request to execute a web server side program. While they both accomplish the same task, their methods of doing so are quite different.
The GET Method

In the GET method , all of the form data that has been captured is appended to the request string when a GET request is issued. The data is appended to the request string using key =value pairs. A GET request that looks like: AnilSingh&age=23&qule=mcalko

would execute a script named example.jsp available in the captainganj directory of the domain and pass it a value of AnilSingh which will be held in side the variable name and mcalko which will be held inside the variable show.

Note: The default method used by Browsers for all web requests is the GET method. The response to GET method is cacheable. This means that if some previous results for the request URL exist in the cache, then the older results might be displayed which might not be what is expected by the person who write the program.

Another potential problem with using the GET method is that the total amount of the data can be streamed to the web server is limited to 1024 bytes.
since it has to encoded in to the URL.
The POST Method

In the POST method , the browser use the POST command to submit the data to the web server and includes the form data as part of the request body. The web server read the data from the input files and parses out the variable names an values.

Note: The POST method allows as much data as a required to the passed to the web server because the browser sends the data as a separate text data stream to the web server.
Different Between GET/POST Method

GET Method
1: The GET method send the data to the web server in the limited size. The limited size is 1024 bytes.
2: The execution time of the GET method is very fast then the POST method.
3: The GET method is not grater secure then the POST method.

POST Method
1: The POST method send the data to the web server in the unlimited size (more then 1024 bytes ).
2: The execution time of POST method is slow then GET method.
3: The POST method is much more secure because the query data send the encrypted form.

Sunday, January 25, 2009

JSP Action Tags

This is the another type of tag, it is used to transfer the control between

pages and is also used to enable the use of server side JavaBeans. Instead of
using Java code, the programmer uses special JSP action tags to
either link to a Java Bean set its properties, or get its

Syntax of Action Tag: "<jsp:action attributes />"

There are so many action tags available for Java Server Pages.
The most commonly used action tags are three of them that are:

  1. include

  2. forward

  3. useBean

1. Include Action Tag:- It has the same concept as that of the

include directive. The include tag
is used to include either static or dynamic content, wherever required.

Syntax of include action Tag: <jsp:include page="{relativeURL | <%=

expression %>}" flush="true" />

If the file is dynamic one can use the syntax as below:

<jsp:include page="{relativeURL | <%= expression %>}" flush="true" />

<jsp:param name="parameterName" value="{parameterValue
| <%= expression %>}" />


For example: An example to include a static file jsp-directives.html

in the include action tag:

<jsp:include page="jsp-directives.html"


Let us see an example of dynamic file inclusion in the include action tag

which is done as below:

<jsp:include page="test/jsp-directives.html.jsp">

<jsp:include name="username" value="sandeep" />


2. Forward Action Tag:- The forward action tag is used to transfer
control to a static or dynamic resource. The static or dynamic resource to which
control has to be transferred is represented as a URL. The user can have the
target file as an HTML file, another JSP file, or a servlet. Any of the above is

Syntax of forward action Tag: &nbsp;

<jsp:forward page="{relativeURL | <%= expression %>}" />

Now another representation for forward action Tag is as:

<jsp:forward page ="{relativeURL | <%= expression %>}" />

<jsp:param name ="parameterName" value="parameterValue"
| <%= expression %>}" />


3. useBean Action Tag:- The useBean action tag is the most commonly

used tag because of its powerful features. It allows a JSP to create an instance
or receive an instance of a Java Bean. It is used for creating or instantiating
a bean with a specific name and scope. This is first performed by locating the
instance of the bean.

Syntax of useBean action Tag is:

<jsp:useBean id="beanInstanceName" scope="page|request|session|application"


class="package.class" | type="package.class"

class="package.class" type="package.class" |

beanName="{package.class | <%=
expression %>}"



{ /> |

> other elements



There are the several attributes available in useBean Action Tag, that is:

  • id: This refers to a variable that is case sensitive, identifying
    the bean within scope attribute defined.

  • scope: This refers to the scope of the existence of bean. The
    default scope is page.

  • class: The class name is mentioned and using this bean is
    Instantiated. The data type to which bean must be assigned is mentioned in

  • beanName: When this is specified, the bean is instantiated by the
    java.beans.Beans.instantiate method.

JSP Directives

In this section, you will study about the Directive tag. It allows the JSP engine to processes the page. By using the directive tag, user can import different packages, handles the errors, or session information of JSP page. These are classified in three categories:

  1. Page
  2. Include
  3. Tag Lib

Syntax and usage of directive tag :

1. Page Directives: There are the many attributes are available for page directives which is used to give the special processing information to the JSP Engine that are:

  • language
  • extends
  • import
  • session
  • buffer
  • autoFlush
  • isThreadSafe
  • info
  • errorPage
  • IsErrorPage
  • contentType

language:- This attribute is used to denote the language used by a file. Language denotes the scripting language used in script lets, declarations, and expressions in the JSP page and any included files.

Syntax of language attribute is: <%@ page language = "java" %>

extends:- This is used to signify the Super class of the Java class used by the JSP engine for the translated Servlet.

Syntax of extends attribute is: <%@ page extends = "package.class"%>

import:- The import attribute is used to import all the classes in a java package into the current JSP page. With this facility, the JSP page can use other java classes.

Syntax of import attribute is: <%@ page import = "java.util.*" %>

session:- The session attribute, when set to true, sets the page to make use of sessions. by default, the session attribute value is set to true.

Syntax of session attribute is: <%@ page session="true|false" %>

buffer:- It controls the use of buffered output for a JSP page then the buffer attribute can be made use of for achieving this.

Syntax of buffer attribute is: <%@ page buffer = "none|8kb|sizekb" %>

autoFlush:- This attribute is used to specify whether automatically flush out the output buffer when it is full or not.

Syntax of autoFlush attribute is: <%@ page autoFlush = "true|false" %>

isThreadSafe:- This attribute is used to set whether the generated Servlet handles multiple requests or single requests, depending on the set value of true or false. isThreadSafe attribute is used to set and ensure whether thread safety is implemented in the JSP page.

Syntax of isThreadSafe attribute is: <%@ page isThreadSafe="true|false" %>

info:- Programmers make use of info attribute to place the information or documentation for a page. Details such as: author, version, copyright and date are placed in this attribute. This is actually text string that is written as input text in the compiled JSP page.

Syntax of info attribute is: <%@ page info = "text" %>

errorPage:- If the programmer wants to place errors in a different page then the URL to the error page can be mentioned in this attribute as errorPage.

Syntax of errorPage attribute is: <%@ page errorPage = "relativeURL" %>

isErrorPage:- This attribute is used to specify whether or not a JSP page displays an error page by setting the value as true or false. By default, the value is set to false, meaning that the user cannot make use of the exception object in the JSP page. If the value is set to true, then it means that the user can make use of the exception object in the JSP page.

Syntax of isErrorPage attribute is: <%@ page isErrorPage="true|false" %>

contentType:- This attribute is used to set the mime type and character set of the JSP. The user can make use of any MIME type or character set valid for the JSP container.

Syntax of contentType attribute is: <%@ page contentType="mimeType [; charset=characterSet]" %>

2. Include Directives:- This is a type of directive tag. If a programmer wants to include contents of a file inside another, then the Include directive is used. The file included can be either static ( HTML file) or dynamic (i.e., another tag file). The Include directive is used to include the contents of other file in the current tag file.

Syntax of Include directive is: <%@ include file = "xxx.html/xx.tagf"%>

For example: The user includes a dynamic file in the include directive: <%@ include file="javasks.tagf" %>.

3. Tag Lib Directives:- A user can customize actions from their tag file using the Tag Lib directive. The Tag Lib directive is a collection of custom tags.

The syntax of Tag Lib directive is: <%@ taglib uri = "tag library URI" prefix = "tag Prefix" %>

scriptlet tag:- This tag is a type tag used for inserting Java Code into JSP. Notation of the Scriptlet tag is: <% %>

Reference Sit:-

Friday, January 23, 2009

Life Cycle of JSP

JSP technology enables us to create web based application. It sends its request as a Servlet. Therefore, the life cycle and many of the capabilities of JSP pages (in particular the dynamic aspects) are determined by Java Servlet technology.

A Servlet handles the request that is mapped to a JSP page and checks whether the JSP page's servlet is older than the JSP page. Then it translates the JSP page into a servlet class and compiles the class.

JSP Life Cycle has three important methods that is:

  1. init():- This method is called when the instance is created and it is called only once during JSP life cycle. It is called for the Servlet instance initialization.
  2. service:- This method is called for every request of this JSP during its life cycle. It passes the request and the response objects. jspService() cannot be overridden.
  3. destroy():- This method is called when this JSP is destroyed and will not be available for future requests.

Phases of JSP Life Cycle:

  1. Translation:
    The JSP source file generates a java servlet file. Generated servlet implements the interface javax.servlet.jsp.HttpJspPage. The interface HttpJspPage extends the interface JspPage. This interface JspPage extends the interface javax.servlet.Servlet.
  2. Compilation:
    The generated java servlet file is compiled into a java servlet class. The generated servlet class thus implements all the methods of the above said three (javax.servlet.jsp.HttpJspPage, JspPage, javax.servlet.Servlet) interfaces.
  3. Class Loading:
    The java servlet class that was compiled from the JSP source is loaded into the container.
  4. Instance Creation:
    An instance is created for the loaded servlet class. The interface JspPage contains jspInit() and jspDestroy(). The JSP specification has provided a special interface HttpJspPage for JSP pages serving HTTP requests and this interface contains _jspService().

JavaServer Pages technology

JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. The JSP specification, developed through an industry-wide initiative led by Sun Microsystems, defines the interaction between the server and the JSP page, and describes the format and syntax of the page.

Wednesday, January 21, 2009

JSP Scriptlet Question and Answer

  1. I have created two buttons in a JSP page.i want to go to one page when button1 is clicked and to other page when button2 is can i do this?..Plz help me..
  2. Write the JSP command which includes sub_page.jsp and passing in parameters as below: Parameter: ?age? Value: ?33? Parameter: ?place? Value: ?petaling jaya?
  3. I m sending my data frm one page. The second page process it & saves to database and display message like DATA SAVED on same page(second). If I refresh the browser the same query re-execute & again same data store. How Can I check this(I meanwithout using sendredirect to another page)
  4. What is the max limit of parameters that can be passed from Form.
  5. How can I restrict the user from Clicking of Back button in any browser?
  6. Why HTML is called as a language?
  7. What is the widely used web programming technology? what is the advantages of JSP among other technologies?
  8. I have to view(in a JSP Page)the rows in a database which contains some thousands of rows.But in a page i have to view only 20 rows and by pressing the hyperlinks in the page(for an example :page1, page2)i have to view the rest of the records. Each page should contain 20 records only. Kindly give me an idea or some sample coddings to design the above JSP page.
  9. How to compile the JSP pages manually in all applications and web servers
  10. How are the implicit object made available in the jsp file? Where are they defined?
  11. Can one JSP or Servlet extend another Servlet or JSP
  12. suppose we have 1000 rows in the database i need to retrive 200 rows per page, then which approach is better either struts based or non struts based it is an interview question
  13. What is the difference between declaring the variables in the scriptlet tags and in the declaration tags?
  14. What is the differene between include directive and include action?
  15. What is difference between JSP 1.0 model and JSP 2.0 model
  16. What is jsp:usebean. What are the scope attributes & difference between these attributes
  17. How can we move from one JSP page to another(mean using what tecnique?)
  18. How can you include a static file in JSP page. is it possible in html style sheet. which one is better jsp's include directive ("<%@include="filename"%>) or html's style sheet.
  19. Can we implements interface or extends class in JSP?
  20. How can we move from one JSP page to another(mean using what tecnique?)