Posted on August 12, 2008 by sharat
Use the jspInit() method to cache static data, and release them in the jspDestroy() method. Use the jspInit() method to cache static data. Use StringBuffer rather than using + operator when you concatenate multiple strings. Use the print() method rather than the println() method. Use a ServletOutputStream rather than a PrintWriter to send binary data. [...]
Filed under: JSP, Performance | Leave a Comment »
Posted on September 8, 2006 by sharat
The <c:import> tag imports a resource specified by a URL and exposes it to the page, variable, or reader. The <jsp:include> standard action is a request-time action that will include the output of another JSP at the location of the tag within the calling JSP. <c:import> is similar to the <jsp:include> directive, but with more features. [...]
Filed under: JSP | 5 Comments »
Posted on September 7, 2006 by sharat
This implicit object represents the application to which the JSP belongs. JSPs are grouped into applications according to their URLs where the first directory name in a URL defines the application. The application object contains methods that provide information about the JSP Container, support for logging plus utility methods for example translating a relative URL [...]
Filed under: JSP | Leave a Comment »
Posted on September 7, 2006 by sharat
The session implicit object is used to provide an association between the client and the server. This association, or session, persists over multiple connections and/or requests during a given time period. Sessions are used to maintain state and user identity across multiple page requests. A session can be maintained either by using cookies or by [...]
Filed under: JSP | 2 Comments »
Posted on September 7, 2006 by sharat
The response object handles the output to the client. This object can be used for creating HTTP Headers, creating cookies, setting content type and redirecting workflow. Servlet Class javax.servlet.http.HttpServletResponse The following table summarises the most useful methods available to the response object. Method Description setContentType() Sets the MIME type and character encoding for the page. [...]
Filed under: JSP | Leave a Comment »
Posted on September 7, 2006 by sharat
The request object retrieves the values that the client browser passed to the server during an HTTP request such as headers, cookies or parameters associated with the request. Among the most common use of the request object is to obtain parammeter or query string values. Servlet Class javax.servlet.HttpServletRequest The following table summarises the most useful [...]
Filed under: JSP | 1 Comment »
Posted on September 6, 2006 by sharat
The Java Standard Tag Library (JSTL) is a standardized collection of custom tags. It has a number of tags for common tasks such as iterating through lists, interacting with databases, handling XML data, formatting data, and much more. The latest version of JSTL is 1.1. An implementation of JSTL can be downloaded from the Apache [...]
Filed under: JSP | 9 Comments »
Posted on September 6, 2006 by sharat
Separation of static from dynamic content. Write Once Run Anywhere. Dynamic content can be served in a variety of formats. example: browsers using HTML/DHTML, to handheld wireless devices like mobile phones and PDAs using WML, to other B2B applications using XML Recommended Web access layer for n-tier architecture. Completely leverages the Servlet API.
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
JSP Expression <%= expression %> Expression is evaluated and placed in output. XML equivalent is<jsp:expression>expression</jsp:expression>. Predefined variables are request,response,out,session,application,config, andpageContext (available in scriptlets also). JSP Scriptlet <% code %> Code is inserted in service method. XML equivalent is<jsp:scriptlet>code</jsp:scriptlet>. JSP Declaration <%! code %> Code is inserted in body of servlet class, outside of service method. [...]
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
The getCookies() method of the request object returns an array of Cookie objects. Cookies are used to allow web browsers to hold small amounts of information or state data associated with a user’s web browsing. Cookies are named and have a single value. They may have optional attributes, including a comment presented to the user, [...]
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
The session implicit object is used to provide an association between the client and the server. This association, or session, persists over multiple connections and/or requests during a given time period. Sessions are used to maintain state and user identity across multiple page requests. A session can be maintained either by using cookies or by [...]
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
There are a number of problems that arise from the fact that HTTP is a “stateless” protocol. In particular, when you are doing on-line shopping, it is a real annoyance that the Web server can’t easily remember previous transactions. This makes applications like shopping carts very problematic: when you add an entry to your cart, [...]
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
The JSP super class and sub-class need to satisfy certain requirements as defined in the sections below. First let us assume we are using the HTTP protocol. Then mapping of other protocols is an easy task. Requirements for the Super Class It must implement the HttpJspPage interface. It will obviously extend the HttpServlet class. It [...]
Filed under: JSP | Leave a Comment »
Posted on September 6, 2006 by sharat
* The use of JavaBeans within JSP pages is a system for accessing Java components through the standard interface of methods with set and get prefixes. * The general syntax for the useBean tag is as follows. <jsp:useBean id=”myBean” type=”classtype” class=”com.domain.ClassName” scope=”session” /> # The it attribute id mandatory and can be an arbitrary [...]
Filed under: JSP | 2 Comments »
Posted on September 5, 2006 by sharat
Variable declared inside declaration part is treated as a global variable.that means after convertion jsp file into servlet that variable will be in outside of service method or it will be declared as instance variable. the scope is available to complete jsp and to complete in the converted servlet class. Variable declared inside a scriplet [...]
Filed under: JSP | 16 Comments »
Posted on September 5, 2006 by sharat
Session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to [...]
Filed under: JSP | Leave a Comment »
Posted on September 5, 2006 by sharat
You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing page. For example: <%@ page errorPage=”error.jsp” %> redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing. Within error.jsp, if you indicate that it is an error-processing [...]
Filed under: JSP | 3 Comments »
Posted on September 5, 2006 by sharat
A JSP page services requests as a servlet. Thus, the life cycle and many of the capabilities of JSP pages (in particular the dynamic aspects) are determined by Java Servlet technology. JSP page translation JSP page compilation load class create instance call the jspInit method call the _jspService method call the jspDestroy method When [...]
Filed under: JSP | 4 Comments »
Posted on August 29, 2006 by sharat
You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy().The jspInit() [...]
Filed under: JSP | 2 Comments »
Posted on August 29, 2006 by sharat
servlet life cycle methods: init(); service(); destroy(); jsp lifecycle methods: init(); _service(); destroy(); remember starting any method with _ means we cannot override this method.
Filed under: JSP | 6 Comments »
Posted on August 29, 2006 by sharat
In an HttpServletResponse class: Response.sendRedirect () This function is used, when we want to redirect the client request to some other site (i.e out of our context) or when ever we want to redirect errors. If you are using sendRedirect (), then it will be visible to the client that means the URL which you [...]
Filed under: JSP | 3 Comments »
Posted on August 29, 2006 by sharat
DoGet DoPost In doGet Method the parameters are appended to the URL and sent along with header information In doPost, parameters are sent in separate line in the body Maximum size of data that can be sent using doget is 240 bytes There is no maximum size for data Parameters are not encrypted Parameters are [...]
Filed under: JSP | 63 Comments »
Posted on August 29, 2006 by sharat
Every Servlet contains a doGet or doPost method. When we deploy a servlet the init method of the servlet is called. And after it has been deployed on each request of the servlet a separate thread is created to process the doGet/doPost method of the servlet. So all the instance variables of the servlet are [...]
Filed under: JSP | 10 Comments »
Posted on August 29, 2006 by sharat
Page -
Filed under: JSP | 2 Comments »
Posted on August 29, 2006 by sharat
Implicit objects let developers access container-provided services and resources. These objects are defined as implicit because you do not have to explicitly declare them. They are defined in every JSP page and used behind the scenes by the container whether you declare them or not — although you cannot redeclare them. Because implicit objects are [...]
Filed under: JSP | 3 Comments »
Posted on August 29, 2006 by sharat
A PageContext instance provides access to all the namespaces associated with a JSP page, provides access to several page attributes, as well as a layer above the implementation details. Implicit objects are added to the pageContext automatically. The PageContext class is an abstract class, designed to be extended to provide implementation dependent implementations thereof, by [...]
Filed under: JSP | 1 Comment »
Posted on August 28, 2006 by sharat
A JSP page can include page fragments from other files to form the complete response. You can use this, for instance, to keep header, footer, and navigation bar content in separate files and include them in all other pages. There are two include mechanisms: the include directive and the include action. It’s not always obvious [...]
Filed under: JSP | 13 Comments »
Posted on August 28, 2006 by sharat
extends=”package.class” The fully qualified name of the superclass of the Java class file this JSP file will be compiled to. Use this attribute cautiously, as it can limit the JSP container’s ability to provide a specialized superclass that improves the quality of the compiled file. import=”{package.class | package.* }, …” A comma-separated list of Java [...]
Filed under: JSP | Leave a Comment »
Posted on August 28, 2006 by sharat
Declaring a variable in JSP means it will have a scope of page while declaring it in jspInit() means its scope gets end with init() method only.
Filed under: JSP | Leave a Comment »
Posted on August 28, 2006 by sharat
Appropriate HTTP header attributes have to be set to prevent the dynamic content output by the JSP page from being cached by the browser. The following jsp code has to be included at the beginning of your JSP pages to prevent caching : Execute the following scriptlet at the beginning of your JSP pages to [...]
Filed under: JSP | Leave a Comment »
Posted on August 28, 2006 by sharat
A J2EE application contains J2EE modules, which could be web applications, EJBs and application clients. It also contains meta-information about the application as well as shared libraries. You can also say that a J2EE application is a set of J2EE modules with some added glue that binds them together into a complete integrated application. The [...]
Filed under: JSP | 2 Comments »
Posted on August 27, 2006 by sharat
Implicit objects are a set of Java objects that the JSP Container makes available to developers in each page. These objects may be accessed as built-in variables via scripting elements and can also be accessed programmatically by JavaBeans and Servlets. These objects will be automatically instantiated under specific variable names hence the name implicit. Object [...]
Filed under: JSP | 2 Comments »
Posted on August 27, 2006 by sharat
Tomcat uses the /tomcat/bin/jspc.bat file to make java servlets out of the JSPs. Run this program without parameters to view the help screen. It’s pretty simple and easy to use. You can set up another bat file to call it with parameters. Make sure to include the param “-p org.apache.jsp” to create all servlets in [...]
Filed under: JSP | 2 Comments »
Posted on August 27, 2006 by sharat
Extending a JSP from another servlet or JSP can be a very tricky task. However it is not recommended by sun, because in doing so you restrict the capability of the JSP Engine. The JSP super class and sub-class need to satisfy certain requirements. Requirements for the Super Class
Filed under: JSP | 1 Comment »