Sunday, February 4, 2007

What is Server-Side Includes (SSI)?

Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an .shtml extension.

SOURCE : www.referjava.com

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

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.

SOURCE : www.referjava.com

Why we are used setMaxAge() and getMaxAge() in Cookies ?

setMaxAge
public void setMaxAge(int expiry)
Sets the maximum age of the cookie.The cookie will expire after that many seconds have passed.Negative values indicate the default behaviour:the cookie is not stored persistently, and will be deleted when the user agent exits.A zero value causes the cookie to be deleted

getMaxAge():
public int getMaxAge()
Returns the maximum specified age of the cookie. If none was specified, a negative value is returned, indicating the default behaviour described with setMaxAge.

SOURCE : www.referjava.com

What are the methods in HttpSession and use of those methods?

a) getCreationTime()
Returns the time at which this session representation was created.

b) getId()
Returns the identifier assigned to this session.

c) getLastAccessedTime()
Returns the last time the client sent a request carrying the identifier assigned to the session.

d) getSessionContext()
Returns the context in which this session is bound.

e) getValue(String)
Returns the object bound to the given name in the session's application layer data.

f) getValueNames()
Returns an array of the names of all the application layer data objects bound into the
session.

g) invalidate()
Causes this representation of the session to be invalidated and removed from its context.

h) isNew()
A session is considered to be "new" if it has been created by the server, but the client has
not yet acknowledged joining the session.

j) putValue(String, Object)
Binds the specified object into the session's application layer data with the given name.

k) removeValue(String)
Removes the object bound to the given name in the session's application layer data.

SOURCE : www.referjava.com

What are the different servers available for developing and deploying Servlets?

a) JRun2.0--Allaire
b) Apache --jserv
c) jwsdk2.0 --sun
d) servletexec
e) Tomcat webserver--tomcat
f) Weblogic AS--BEA Systems
g) NetDynamics5.0--sun
h) Iplanet--sun&netscape
i) Netscape--netscape
g) IBM websphere--IBM
h) oracle--oracle
i) Proton-Pramati technologies

SOURCE : www.referjava.com

Is it possible to communicate from an applet to servlet and how many ways and how?

Yes, there are three ways to communicate from an applet to servlet and they are:

a) HTTP Communication(Text-based and object-based)
b) Socket Communication
c) RMI Communication
(You can say, by using URL object open the connection to server and get the InputStream from
URLConnection object).
Steps involved for applet-servlet communication:
step: 1 Get the server URL.
URL url = new URL();
step: 2 Connect to the host
URLConnection Con = url.openConnection();
step: 3 Initialize the connection
Con.setUseCatches(false):
Con.setDoOutput(true);
Con.setDoInput(true);
step: 4 Data will be written to a byte array buffer so that we can tell the server the length of the data.
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
step: 5 Create the OutputStream to be used to write the data to the buffer.
DataOutputStream out = new DataOutputStream(byteout);

SOURCE : www.referjava.com

Why should we go for interservlet communication?

Servlets running together in the same server communicate with each other in several ways.
The three major reasons to use interservlet 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)

SOURCE : www.referjava.com