Saturday, November 22, 2025
HomeLanguagesJavaServlet – Server Side Include (SSI)

Servlet – Server Side Include (SSI)

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS