How to Improve JSP Page performance

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. [...]

40. What is the difference between <jsp:include> and <c:import>

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. [...]

36. Sir, do you know about jsp application object

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 [...]

35. Tell me something about jsp session object

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 [...]

34. What do you know about jsp response object

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. [...]

33. Explain request implicit object

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 [...]

30. Explain the advantages of JSTL

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 [...]

29. What are the advantages of JSP

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.

28. Explain JSP Basic Structure Items.

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. [...]

27. How to handle cookies in JSP

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, [...]

26. Explain JSP Session implicit Object.

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 [...]

25. What is Session Tracking.

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, [...]

24. How can JSP inheritance be achieved

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 [...]

23. Explain about JSP Standard Action

* 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 [...]

22. Discuss the scope of a variable declared in Declaration part and in scriptlet part.

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 [...]

21. How can I enable session tracking for JSP pages if the browser has disabled cookies?

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 [...]

20. How does JSP handle run-time exceptions

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 [...]

19. Explain the life cycle of a JSP.

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 [...]

18. How to overwrite the init and destroy method in a jsp page

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() [...]

17. What are Servlet and JSP lifecycle methods.

servlet life cycle methods: init(); service(); destroy(); jsp lifecycle methods: init(); _service(); destroy(); remember starting any method with _ means we cannot override this method.

16.What is the difference between sendRedirect()and forward()in JSP?

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 [...]

15. What is the difference between Difference between doGet() and doPost()

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 [...]

14. Explain JSP/Servle threading model.

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 [...]

13. what is the default scope of jsp tags?

Page -

12. What are the default objects provided by JSP container?

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 [...]

11.What object that provides one point access to page, request, response, session, out, exception, config and application

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 [...]

10. what is the difference between , pagedirective include, action tag include ?

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 [...]

9. Explain JSP Import and JSP Extends.

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 [...]

8. What is the diff. b/n declaring members in the JSP and declaraing in jspinit() method ?

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.

1. How do I prevent the output of my JSP or Servlet pages from being cached by the browser?

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 [...]

5. Can a single JSP page be considered as a J2EE application?  

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 [...]

3.How are the implicit object made available in the jsp file? Where are they defined?

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 [...]

2.How to compile the JSP pages manually in all applications and web servers

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 [...]

1. Can One Jsp/Servlet extend another Servlet/Jsp

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

Follow

Get every new post delivered to your Inbox.