40. What is the meaning of response has already been committed error?
You will get this error only when you try to redirect a page after you already have flushed the output buffer. This happens because HTTP specification force the header to be set up before the lay out of the page can be shown. When you try to send a redirect status, your HTTP server cannot send it right now if it hasn’t finished to set up the header. Simply it is giving the error due to the specification of HTTP 1.0 and 1.1
42. How do I use a scriptlet to initialize a newly instantiated bean?
A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated (Only at the time of instantiation.) Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone.
43. What is JSP?
JSP is a server side scripting technology. JSP allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix must ends with .jsp.
44. What are JSP Actions?
JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include: jsp:include, jsp:useBean, jsp:setProperty, jsp:getProperty, jsp:forward and Jsp: plugin
45. What is the difference between ServletContext and ServletConfig?
The ServletConfig gives the information about the servlet initialization parameters. The servlet engine implements the ServletConfig interface in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface to the servlet’s init() method. The ServletContext gives information about the container. The ServletContext interface provides information to servlets regarding the environment in which they are running. It also provides standard way for servlets to write events to a log file.
46. How can a servlet refresh automatically?
We can use a client-side Refresh or Server Push
47. What is Server side push?
Server Side push is useful when data needs to change regularly on the clients application or browser, without intervention from client. The mechanism used is, when client first connects to Server, then Server keeps the TCP/IP connection open.
48. What is client side refresh?
The standard HTTP protocols ways of refreshing the page, which is normally supported by all browsers.
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=/servlet/MyServlet/">
This will refresh the page in the browser automatically and loads the new data every 5 seconds.
49. What is the Max amount of information that can be saved in a Session Object ?
There is no such limit on the amount of information that can be saved in a Session Object. The only limit is the Session ID length , which should not exceed more than 4K.
50. Why should we go for inter servlet communication?
The three major reasons to use inter servlet communication are: a) Direct servlet manipulation – allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object) b) Servlet reuse – allows the servlet to reuse the public methods of another servlet. c) Servlet collaboration – requires to communicate with each other by sharing specific information (through method invocation)
51. What is a output comment?
A comment that is sent to the client in the viewable page source. The JSP engine handles an output comment as un interpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.
52. What is a Hidden Comment
Hidden Comments are JSP comments. A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags.
53. What are the differences between a session and a cookie?
Session is stored in server but cookie stored in client. Session should work regardless of the settings on the client browser. There is no limit on the amount of data that can be stored on session. But it is limited in cookie. Session can store objects and cookies can store only strings. Cookies are faster than session.
54. What is HttpTunneling?
HTTP tunneling is used to encapsulate other protocols within the HTTP or HTTPS protocols. Normally the intranet is blocked by a firewall and the network is exposed to the outer world only through a specific web server port, that listens for only HTTP requests. To use any other protocol, that by passes the firewall, the protocol is embedded in HTTP and send as HttpRequest.
55. How to pass information from JSP to included JSP?
By using tag.
56. What is the better way to enable thread-safe servlets and JSPs? SingleThreadModel Synchronization?
The better approach is to use synchronization. Because SingleThreadModel is not scalable. SingleThreadModel is pretty resource intensive from web server’s perspective. The most serious issue is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the un serviced requests are queued until something becomes free – which results in poor performance.
57. What is the difference between ServletContext and PageContext?
ServletContext gives the information about the container and PageContext gives the information about the Request
58. Why in Servlet 2.4 specification SingleThreadModel has been deprecated?
SingleThreadModel is pretty resource intensive from web server’s perspective. When the number of concurrent requests exhaust the servlet instance pool, all the un serviced requests are queued until something becomes free – which results in poor performance.
59. How do you pass data (including JavaBeans) to a JSP from a servlet?
By forwarding the request to the servlet ( the data must be there in the request scope) we can pass the data from a JSP to servlet. Also we can use a session to pass the data.
60. How can I set a cookie?
Cookie c = new Cookie("name","value");