The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

61.How do you define filters?

Filters are defined in the deployment descriptor file web.xml and then mapped to either servlet or JSP names or URL patterns in your application's deployment descriptor.
When the JSP container starts up your web application, it creates an instance of each filter that you have declared in the deployment descriptor. The filters execute in the order that they are declared in the deployment descriptor.

62.What are cookies?

Cookies are text files stored on the client computer and they are kept for various information tracking purpose.

63.How cookies work?

Cookies are usually set in an HTTP header althoughJavaScriptcanalsosetacookiedirectlyonabrowser.If the browser is configured to store cookies, it will then keep this information until the expiry date. If the user points the browser at any page that matches the path and domain of the cookie, it will resend the cookie to the server.

64.How do you set cookies in the JSP?

  • Creating a Cookie object: You call the Cookie constructor with a cookie name and a cookie value, both of which are strings.
  • Setting the maximum age: You use setMaxAge to specify how long inseconds the cookie should be valid.
  • Sending the Cookie into the HTTP response headers: You use response.addCookie to add cookies in the HTTP response header

65.How to read cookies with JSP?

To read cookies, you need to create an array of javax.servlet.http.Cookie objects by calling the getCookies method of HttpServletRequest. Then cycle through the array, and use getName and getValue methods to access each cookie and associated value.

66.How to delete cookies with JSP?

To delete cookies is very simple. If you want to delete a cookie then you simply need to follow up following three steps:

  • Read an already existing cookie and store it in Cookie object.
  • Set cookie age as zero using setMaxAge method to delete an existing cookie.
  • Add this cookie back into response header.

67.How is Session Management done in JSP?

Session management can be achieved by the use of:

  • Cookies: A webserver can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie.
  • Hidden Form Fields: A web server can send a hidden HTML form field along with a unique session ID as follows:
  • This implies that when the form is submitted, the specified name and value will be getting included in GET or POST method.
  • URL Rewriting: In URL rewriting some extra information is added on the end of each URL that identifies the session. This URL rewriting can be useful where a cookie is disabled.
  • The session Object: JSP makes use of servlet provided HttpSession Interface which provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user.

68.How can you delete a session data?

When you are done with a user's session data, you have several options:

  • Remove a particular attribute: You can call public void removeAttributeStringname method to delete the value associated with a particular key.
  • Delete the whole session: You can call public void invalidate method to discard an entire session.
  • Setting Session timeout: You can call public void setMaxInactiveIntervalintinterval method to set the timeout for a session individually.
  • Log the user out: The servers that support servlets 2.4, you can call logout to log the client out of the Web server and invalidate all sessions belonging to all the users.
  • web.xml Configuration: If you are using Tomcat, apart from the above mentioned methods, you can configure session time out in web.xml file as follows.

69.How can you upload a file using JSP?

To upload a single file you should use a single (input .../) tag with attribute type="file".To allow multiple files uploading, include more than one input tags with different values for the name attribute.

70.Where will be the uploaded files stored?

You can hard code this in your program or this directory name could also be added using an external configuration such as a context-param element in web.xml.

71.What is JSP page redirection?

Page redirection is generally used when a document moves to a new location and we need to send the client to this new location or may be because of load balancing, or for simple randomization.

72.What is the difference between (jsp:forward page = ... ) and response.sendRedirecturl?

The element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file.
sendRedirect sends HTTP temporary redirect response to the browser, and browser creates a new request to go the redirected page.

73.What is a hit count for a web page?

A hit counter tells you about the number of visits on a particular page of your web site.

74.How do you impement hit counter in JSP?

To implement a hit counter you can make use of Application Implicit object and associated methods getAttribute and setAttribute.
This object is a representation of the JSP page through its entire lifecycle. This object is created when the JSP page is initialized and will be removed when the JSP page is removed by the jspDestroy method.

75.How can you implement hit counter to avoid loss of count data with each restart of thh application?

You can follow the below steps:

  • Define a database table with a single count, let us say hitcount. Assign a zero value to it.
  • With every hit, read the table to get the value of hitcount.
  • Increase the value of hitcount by one and update the table with new value.
  • Display new value of hitcount as total page hit counts.
  • If you want to count hits for all the pages, implement above logic for all the pages.

76.What is auto refresh feature?

Consider a webpage which is displaying live game score or stock market status or currency exchange ration. For all such type of pages, you would need to refresh your web page regularly using refresh or reload button with your browser.
JSP makes this job easy by providing you a mechanism where you can make a webpage in such a way that it would refresh automatically after a given interval.

77.How do you implement the auto refresh in JSP?

The simplest way of refreshing a web page is using method setIntHeader of response object. Following is the signature of this method:
public void setIntHeader(String header, int headerValue)
This method sends back header "Refresh" to the browser along with an integer value which indicates time interval in seconds.

78.What is JSTL?

The JavaServer Pages Standard Tag Library JSTL is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags.

79.What the different types of JSTL tags are ?

Types of JSTL tags are:

  • Core Tags
  • Formatting tags
  • SQL tags
  • XML tags
  • JSTL Functions

80.What is the use of (c:set ) tag?

The (c:set ) tag is JSTL-friendly version of the setProperty action. The tag is helpful because it evaluates an expression and uses the results to set a value of a JavaBean or a java.util.Map object.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com