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
1. HEAD
2. GET
3. POST
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:
http://www.worldinfosoft.com/captainganj/example.jsp?name= AnilSingh&age=23&qule=mcalko
would execute a script named example.jsp available in the captainganj directory of the www.worldinfosoft.com 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
pages and is also used to enable the use of server side JavaBeans. Instead of
using
either link to a
properties.
There are so many action tags available for
The most commonly used action tags are three of them that are:
- include
- forward
- useBean
include directive. The include tag
is used to include either static or dynamic content, wherever required.
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"flush="true"/>
Let us see an example of dynamic file inclusion in the include action tagwhich is done as below:
<jsp:include page="test/jsp-directives.html.jsp"><jsp:include name="username" value="sandeep" />
</jsp:include>
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
permitted.
<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.
<jsp:useBean id="beanInstanceName" scope="page|request|session|application"
class="package.class" | type="package.class"
|
beanName="{package.class | <%=
expression %>}"
}
{ /> |> other elements
</jsp:useBean>}
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
type. - 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:
- Page
- Include
- 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
Syntax of import attribute is: <%@ page import = "java.util.*" %>
session:-
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
Reference Sit:- http://www.exforsys.com/tutorials/jsp/jsp-directive-tag.html.
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:
- 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.
- 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.
- destroy():- This method is called when this JSP is destroyed and will not be available for future requests.
Phases of JSP Life Cycle:
- 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. - 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. - Class Loading:
The java servlet class that was compiled from the JSP source is loaded into the container. - 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
Wednesday, January 21, 2009
JSP Scriptlet Question and Answer
- 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 clicked..how can i do this?..Plz help me..
- Write the JSP command which includes sub_page.jsp and passing in parameters as below: Parameter: ?age? Value: ?33? Parameter: ?place? Value: ?petaling jaya?
- 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)
- What is the max limit of parameters that can be passed from Form.
- How can I restrict the user from Clicking of Back button in any browser?
- Why HTML is called as a language?
- What is the widely used web programming technology? what is the advantages of JSP among other technologies?
- 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.
- How to compile the JSP pages manually in all applications and web servers
- How are the implicit object made available in the jsp file? Where are they defined?
- Can one JSP or Servlet extend another Servlet or JSP
- 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
- What is the difference between declaring the variables in the scriptlet tags and in the declaration tags?
- What is the differene between include directive and include action?
- What is difference between JSP 1.0 model and JSP 2.0 model
- What is jsp:usebean. What are the scope attributes & difference between these attributes
- How can we move from one JSP page to another(mean using what tecnique?)
- 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.
- Can we implements interface or extends class in JSP?
- How can we move from one JSP page to another(mean using what tecnique?)
Important JSP Interview Question with Solution
- What is JSP?
- What are the lifecycle of JSP?
- What is a translation unit?
- How is JSP used in the MVC model
- What are context initialization parameters
- What is a output comment
- What is a Hidden Comment
- What is a Expression
- What is a Declaration
- What is a Scriptlet
- What are the implicit objects
- What is the difference between forward and sendRedirect
- What are the different scope values for the
- Why are JSP pages the preferred API for creating a web-based client program
- Is JSP technology extensible
- What is difference between custom JSP tags and beans
- How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?
- How does JSP handle run-time exceptions
- How do I prevent the output of my JSP or Servlet pages from being cached by the browser
- How do I use comments within a JSP page
- Response has already been commited error. What does it mean
- How do I use a scriptlet to initialize a newly instantiated bean
- How can I enable session tracking for JSP pages if the browser has disabled cookies
- How can I declare methods within my JSP page
- Is there a way I can set the inactivity lease period on a per-session basis
- How can I set a cookie and delete a cookie from within a JSP page
- How does a servlet communicate with a JSP page
- How do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default
- How can I prevent the word "null" from appearing in my HTML input text fields when I populate them with a resultset that has null values
- How can I get to print the stacktrace for an exception occuring within my JSP page
- How do you pass an InitParameter to a JSP
- How can my JSP page communicate with an EJB Session Bean
- Can we implement an interface in a JSP
- What is the difference between ServletContext and PageContext
- What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()
- How to pass information from JSP to included JSP
- What is the difference between directive include and jsp include
- What is the difference between RequestDispatcher and sendRedirect
- How do I mix JSP and SSI #include