Share on Google+Share on Google+

Java Servlet Change Background Color

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.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();

Hello World

"); } }


After 10 seconds, color will get changed:


Posted on: July 24, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null