Thursday, June 30, 2011

What is a Servlet Filter java

What is a Servlet Filter java

Explain the Servlet Filter?

what purpose used the Servlet Filter?


Filters are not servlets. They do not implement and override HttpServlet methods such as doGet() or doPost(). Rather, a filter implements the methods of the javax.servlet.Filter interface. The methods are:

init()


destroy()


doFilter()


* Intercept a servlet's invocation before the servlet is called
* Examine a request before a servlet is called
* Modify the request headers and request data by providing a customized version of the request object that wraps the real request
* Modify the response headers and response data by providing a customized version of the response object that wraps the real response
* Intercept a servlet's invocation after the servlet is called

A filter implements javax.servlet.Filter and defines its three methods:

1. void init(FilterConfig config) throws ServletException: Called before the filter goes into service, and sets the filter's configuration object
2. void destroy(): Called after the filter has been taken out of service
3. void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException: Performs the actual filtering work


Example

import javax.servlet.*;

public class MyFilter implements javax.servlet.Filter {
public FilterConfig filterConfig; //1

public void doFilter(final ServletRequest request, //2
final ServletResponse response,
FilterChain chain)
throws java.io.IOException, javax.servlet.ServletException {
chain.doFilter(request,response); //3
}

public void init(final FilterConfig filterConfig) { //4
this.filterConfig = filterConfig;
}

public void destroy() { //5
}
}

Tuesday, June 28, 2011

Latest Servlet Interview Question beginner servlet tutorial

1) What is a servlet?
 Answer: Servlets are modules that extend request/response-oriented  servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.

2) What are the classes and  interfaces for servlets?

Answer: There are two packages in servlets and they are javax.servlet and javax.servlet.http.
Javax.servlet contains:
Interfaces Classes
Servlet Generic Servlet
ServletRequest ServletInputStream
ServletResponse ServletOutputStream
ServletConfig  ServletException
ServletContext UnavailableException
SingleThreadModel


Javax.servlet.http contains:
Interfaces    Classes
HttpServletRequest Cookie
HttpServletResponse HttpServlet
HttpSession HttpSessionBindingEvent
HttpSessionContext   HttpUtils
HttpSeesionBindingListener

3)What are the advantage of using Sessions over Cookies and URLReWriting?

Answer: Sessions are more secure and fast becasue they are stored at serverside. But Sessions has to be used combindly with Cookies or URLReWriting for mainting the client id that is sessionid at client side.Cookies are stored  at client side so some clients may disable cookies   so we may not sure that the cookies which  we are mainting  may work  or not but in sessions cookies are disable we can maintain our   sessionid using URLReWriting .In URLReWriting we can’t maintain large data because it leads to    network traffic and access may be become slow.Where as in seesions   will not maintain the data which we have to maintain instead we will maintain only the session id.

What is Servlet chaining ?
Answer: Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.
In servlet chaining, one servlet output is piped to the next servlet  input. This process continues until the last servlet is reached. Its output is then sent back to the client.

1. Include:
    RequestDispatcher rd = req.getRequestDispatcher("Servlet2");
       rd.include(req, resp);

2. Forward, where req is HttpServletRequest and resp is HttpServletResponse:

    RequestDispatcher rd = req.getRequestDispatcher("Servlet3");
     rd.forward(req, resp);

What is a Servlet Filter java


Explain the Servlet Filter?


what purpose used the Servlet Filter?


Filters are not servlets. They do not implement and override HttpServlet methods such as doGet() or doPost(). Rather, a filter implements the methods of the javax.servlet.Filter interface. The methods are:


init()
destroy()
doFilter()


* Intercept a servlet's invocation before the servlet is called
* Examine a request before a servlet is called
* Modify the request headers and request data by providing a customized version of the request object that wraps the real request
* Modify the response headers and response data by providing a customized version of the response object that wraps the real response
* Intercept a servlet's invocation after the servlet is called

A filter implements javax.servlet.Filter and defines its three methods:

1. void init(FilterConfig config) throws ServletException: Called before the filter goes into service, and sets the filter's configuration object
2. void destroy(): Called after the filter has been taken out of service
3. void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException: Performs the actual filtering work



Example

import javax.servlet.*;

public class MyFilter implements javax.servlet.Filter {
public FilterConfig filterConfig; //1

public void doFilter(final ServletRequest request, //2
final ServletResponse response,
FilterChain chain)
throws java.io.IOException, javax.servlet.ServletException {
chain.doFilter(request,response); //3
}

public void init(final FilterConfig filterConfig) { //4
this.filterConfig = filterConfig;
}

public void destroy() { //5
}
}

Wednesday, June 15, 2011

what is a annotation in java and interview questions

Define an Annotation (Annotation Type)

public @interface MyAnnotation {
String doSomething();
}

Example to Annotate Your Code (Annotation)

MyAnnotation (doSomething="What to do")
public void mymethod() {
....
}

Java Annotation Types

There are three annotation types:


  • Marker: Marker type annotations have no elements, except the annotation name itself.


    Example:
    public @interface MyAnnotation {
    }
    Usage:
    @MyAnnotation
    public void mymethod() {
    ....
    }
  • Single-Element: Single-element, or single-value type, annotations provide a single piece of data only. This can be represented with a data=value pair or, simply with the value (a shortcut syntax) only, within parenthesis.

     

    Example:
    public @interface MyAnnotation
    {
    String doSomething();
    }
    Usage:
    @MyAnnotation ("What to do")
    public void mymethod() {
    ....
    }

  • Full-value or multi-value: Full-value type annotations have multiple data members. Therefore, you must use a full data=value parameter syntax for each member.

     

    Example:
    public @interface MyAnnotation {
    String doSomething();
    int count; String date();
    }
    Usage:
    @MyAnnotation (doSomething="What to do", count=1,
    date="09-09-2005")
    public void mymethod() {
    ....
    }

Rules of Thumb for Defining Java Annotation Types

Here are some rules-of-thumb when defining an annotation type:

  1. Annotation declaration should start with an 'at' sign like @, following with an interface keyword, following with the annotation name.
  2. Method declarations should not have any parameters.
  3. Method declarations should not have any throws clauses.
  4. Return types of the method should be one of the following:
    • primitives
    • String
    • Class
    • enum
    • array of the above types

Java Annotation Types

There are two types of annotations available with JDK5:

  • Simple annotations: These are the basic types supplied with Tiger, which you can use to annotate your code only; you cannot use those to create a custom annotation type.
  • Meta annotations: These are the annotation types designed for annotating annotation-type declarations. Simply speaking, these are called the annotations-of-annotations.

Ajax interview questions and answers Latest

AJAX Tips & Tricks

Ajax interview questions and answers


Question :: What is an UpdatePanel Control?
View Answer

An UpdatePanel control is a holder for server side controls that need to be partial postbacked in an ajax cycle. All controls residing inside the UpdatePanel will be partial postbacked. Below is a small example of using an UpdatePanel.
As you see here after running the snippet above, there wont be a full postback exhibited by the web page. Upon clicking the button, the postback shall be partial. This means that contents outside the UpdatePanel wont be posted back to the web server. Only the contents within the UpdatePanel are refreshed.
Explain about the multimedia functions of ajax?
View Answer
Ajax lacks built in multimedia functions. It is not so supportive of inbuilt applications but uses other browser functionalities and plugin`s such as SVG, Quicktime and flash pugin. General multimedia for ajax is achieved through mashup and hack. These multimedia functions can be obtained from outside which helps in building excellent applications.

Are Ajax applications easier to develop than traditional web applications?
View Answer

What are limitations of Ajax?
View Answer
An Ajax Web Application tends to confused end users if the network bandwidth is slow, because there is no full postback running. However, this confusion may be eliminated by using an UpdateProgress control in tandem.

An Ajax Web Application is little bit confused to end users because if there is huge amout of data to show in grid like structure than it may not be worked that why we were put a progress bar to know the end user that there is something going on.

Question :: What is Dojo?
View Answer

Question :: Can Ajax be implemented in browsers that do not support the XmlHttpRequest object?
View Answer


How do I handle concurrent AJAX requests?
View Answer
Question :: How to make sure that contents of an UpdatePanel update only when a partial postback takes place (and not on a full postback)?
View Answer
Should I use XML or text, JavaScript, or HTML as a return type?
View Answer
Are there any security issues with AJAX?
View Answer
What browsers support AJAX?
View Answer
How do I send an image using AJAX?
View Answer
Can AJAX technology work on web servers other than IIS?
View Answer
Explain about web analytics problem with Java?
View Answer
How do I get the XMLHttpRequest object?
View Answer
Question :: How to handle multiple or concurrent requests in Ajax?
View Answer


Should I use an HTTP GET or POST for my AJAX calls?
View Answer

When do I use a synchronous versus a asynchronous request?
View Answer
Not totally. Most browsers offer a native XMLHttpRequest JavaScript object, while another one (Internet Explorer) require you to get it as an ActiveX object....
Question :: Is AJAX code cross browser compatible?
View Answer
How do I test my AJAX code?
View Answer
How do we abort the current XMLHttpRequest in AJAX?
View Answer

What is the XMLHttpRequest object?
View Answer
It offers a non-blocking way for JavaScript to communicate back to the web server to update only part of the web page.

How do I create a thread to do AJAX polling?
View Answer
JavaScript does not have threads. JavaScript functions are called when an event happens in a page such as the page is loaded, a mouse click, or a form element gains focus. You can create a timer using the setTimeout which takes a function name and time in milliseconds as arguments. You can then loop by calling the same function as can be seen in the JavaScript example below.
What is DOJO?
View Answer
Dojo is a third-party javascript toolkit for creating rich featured applications. Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.


Tuesday, June 7, 2011

ANCET 2011 MBA / MCA / ME/ MTech Counselling Status, Procedures and Details Anna University

TANCET 2011 MBA / MCA / ME/ MTech Counselling Status, Procedures and Details Anna University

About TANCET 2011 Exam Result, Anna University


Tamilnadu Common Entrance Test is the common entrance examination conducted by the Anna University for admission to MasterĂ¢€™s level programs. A huge number of students every year apply for the TANCET 2011 exam for securing a seat in the Tamilnadu institutes for the post graduate level.

TANCET 2011 will be conducted for admission to the colleges listed under TANCET examination. For those seeking admission to any of the following Anna University campuses, should take the TANCET 2011 exam & also find TANCET Syllabus, TANCET Question Papers on the official site of TANCET:



    * Anna University, Chennai
    * Anna University Coimbatore
    * Anna University Trichy
    * Anna University, Tirunelveli
    * Govt. Engineering, Arts and Science Colleges
    * Govt. Aided Engineering, Arts & Science Colleges
    * Govt. Quota seats in self-financing Engineering and Arts & Science Colleges / standalone Institutions

TANCET 2011 would be the first step towards a post graduation course from the TANCET colleges in Tamilnadu. Various courses offered through the TANCET 2011 exam are MBA, MCA, & ME / M.Tech. / M.Arch. / M.Plan & more.
WHY LEARNHUB

From news and admission updates to career profiles and study abroad information, from career counselling and guidance to practice tests and expert tips to ace competitive exams, Learnhub is the best guide a student can have to excel in life.
Join Learnhub and benefit from:

1) Our panel of expert counsellors

2) Model test papers for all competitive exams

3) Latest news and admission updates

4) Study Abroad information including loans, visa process & scholarships

5) Ranking of top engineering, DU colleges, B-schools in India & abroad

6) Career options for students of diverse fields