JavaSpartans
Java J2ee Struts Hibernate Spring Interview Questions Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4 5    Next

1. What are the differences between JSP and Servlet ?

There is no difference between JSP and Servlet. 

Basically a JSP is also a Servlet. JSP?s will be converted or compiled into Servlets.
JSP?s are tag based where as Servlets are code based.
JSP?s are for web designers who does not know much about Java, Servlets are for java web developers.
JSP?s are very slow compared to Servlets.
We can extend the functionality of the JSP?s very easily using Custom Tag Libraries but is not possible in Servlets.
JSP?s must be used for presentation logic Where as Servlets must be used for business logic.
The only supported protocol in JSP is HTTP Where as Servlets can support any protocol like HTTP, FTP, and SMTP etc


2. How do you pass data ( including JavaBeans ) to a JSP from a servlet ?

(1) Request Lifetime:
Using this technique to pass beans, a request dispatcher (using either "include" or "forward") can be called. This bean will disappear after processing this request has been completed.
Servlet:
request. setAttribute("theBean", myBean);
RequestDispatcher rd = getServletContext(). getRequestDispatcher("thepage.jsp");
rd. forward(request, response);
JSP PAGE:
(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it.
Servlet: HttpSession session = request. getSession(true);
session. putValue("theBean", myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */
JSP Page:
(3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it.
Servlet: GetServletContext(). setAttribute("theBean", myBean); JSP PAGE:


3. How do you create custom tag libraries i.e your own tags in JSP ?

Please Answer


4. How are Servlets and JSP Pages related ?

JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.


5. What is jsp:forward tag for?

It forward current request to another page. Following is the syntax :
 <jsp:forward page="url"/>


6. How can you create PDF Files in java ?

iText, a JAVA-PDF library - This library contains classes that generate documents in the Portable Document Format (PDF) and/or HTML. (There are lot of other tools are there in market )


7. Is JSP technology extensible ?

YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries


8. How does a servlet communicate with a JSP page?

Servlet can interact with jsp using following code snippet: getServletConfig().getServletContext().getRequestDispatcher ("/jsp/Bean1.jsp").forward(request, response);


9. How can we use beans in JSP?

<jsp:usebean id="beanID" class="fully qualified class name" scope="page|request|session|application">
        <jsp:setProperty name="id" property="someProperty" value="someValue">
        <jsp:getProperty name="id" property="someProperty">


10. How many types of JSP Errors are they ?

JSP Translation Time Errors. JSP Request Time Errors. Errors can occur in a JSP in two different phases of its life. The first type of error, which occurs during the initial request, is known as a translation time error . The second type of JSP error occurs during subsequent requests and is know as a request time error .


Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4 5    Next
Menu - javaspartans.com - Java J2ee Struts Spring Hibernate Interview Questions
Hostens.com - A home for your website
Ads By Google