AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-servlet: what is SSI in servlets?

could you explain the SSI concept with example.



Thanking you.

corejava x 351
servlet x 19
Posted On : 2016-08-11 16:24:31.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
up-rate
5
down-rate

Answers


Server-side includes are useful when a page is primarily static but contains a few distinct dynamic portions. For a simple example, let´s assume we have several pages that need to display the current time. As an extra challenge, let´s assume that sometimes we need the current time in time zones other than our own.

Note:
--------------------------
Html code we need to write in .shtml extension file. Add jar file servlets-ssi-5.0.16.jar and set <Context privileged="true"> in tomcat´s ./conf/context.xml file.

web.xml:
-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet>
<servlet-name>GetDate</servlet-name>
<servlet-class>in.anyforum.GetDate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetDate</servlet-name>
<url-pattern>/getDate</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.shtml</welcome-file>
</welcome-file-list>
</web-app>


index.shtml:
----------------------------------
<HTML>
<HEAD><TITLE>SSI- anyforum.in</TITLE></HEAD>
<BODY>
The current time here is:
<SERVLET CODE=GetDate>
</SERVLET>
</BODY>
</HTML>


GetDate.java:
-------------------------------------------
package in.anyforum;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetDate extends HttpServlet {

public GetDate() {
super();
}

public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Date From Servlet as below");
out.println(Calendar.getInstance().getTime());
out.flush();
out.close();
}

public void init() throws ServletException {
// Put your code here
}

}

Posted On : 2016-08-11 23:57:53
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523187021168
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in