Java Servlet Change Background Color


 

Java Servlet Change Background Color

In this section, you will learn how to to change the background color of the servlet automatically.

In this section, you will learn how to to change the background color of the servlet automatically.

Java Servlet Change Background Color

You can provide an effective way to the web page by changing the background color of the web page. In servlet, you can do this by using javascript. Here, we are going to change the background color of the servlet automatically after every 10 seconds. We have define nine colors in the javascript which should be displayed randomly.

Here is the code:

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ChangeBackgroundColor extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		PrintWriter out = response.getWriter();
		out.println("");
		out.println("");
		out.println("

Hello World

"); } }

Output:

After 10 seconds, color will get changed:

Ads