Skip to content
Related Articles

Related Articles

Servlet – Server Side Include (SSI)

View Discussion
Improve Article
Save Article
  • Last Updated : 14 Feb, 2022
View Discussion
Improve Article
Save Article

Server-side includes are instructions and directives included in a web page that the web server may analyze when the page is provided. SSI refers to the servlet code that is embedded into the HTML code. Not all web servers can handle SSI. so you may read documents supported by a web server before utilizing SSI in your code.

Syntax:

<SERVLET CODE=MyGfgClassname CODEBASE=path initparam1=initparamvalue initparam2=initparam2value>
    <PARAM NAME=name1 VALUE=value1>
    <PARAM NAME=name2 VALUE=value2>
</SERVLET>

Here the path indicates the MyGfgClassname class name path in the server.  you can set up the remote file path also. the remote file path syntax is,

http://server:port/dir

When a server that does not support SSI sees the SERVLET> tag while returning the page, it replaces it with the servlet’s output. The server does not parse all of the pages it returns; only those with a.shtml suffix are parsed. The class name or registered name of the servlet to invoke is specified by the code attributes. It’s not required to use the CODEBASE property. The servlet is presumed to be local without the CODEBASE attribute. The PARAM> element may be used to send any number of parameters to the servlet. The getParameter() function of ServletRequest may be used by the servlet to obtain the parameter values.

Server Side Include (SSI)

Example

index.shtml

HTML




<HTML>
<HEAD><TITLE>GEEKSFORGEEKS</TITLE></HEAD>
<BODY>
    Hello GEEKS, current time is:
    <!-- here the ssi servlet 
         class has been called-->
    <SERVLET CODE=GfgTime>
    </SERVLET>
</BODY>
</HTML>


GfgTime.java

Java




import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GfgTime extends HttpServlet 
{
 private static final long serialVersionUID = 1L;
        public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 
        {
             PrintWriter out = res.getWriter();
             Date date = new Date();
             DateFormat df = DateFormat.getInstance();
               
             // Here write the response shtml file
             out.println("Hello GEEKS, current time is:");
             out.println(df.format(date));
        }
}


web.xml

XML




<web-app>
 <servlet>
    <servlet-name>GfgTime</servlet-name>
    <servlet-class>GfgTime</servlet-class>
 </servlet>
 <servlet-mapping>
    <servlet-name>GfgTime</servlet-name>
    <url-pattern>/index.shtml</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
    <welcome-file>index.shtml</welcome-file>
 </welcome-file-list>
</web-app>


Output:
 

Output


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!