say hello in spanish

In this program we are going to display "hello" in spanish along with the date.

say hello in spanish

say hello in spanish

     

In this program we are going to display "hello" in spanish along with the date.

To make this program we need to make a class SayHelloToSpain. To main logic of the program will be written inside the doGet() method of the servlet. To print "hello" in servlet setHeader() method of the response object should be "es". Here "es" means the content language is spanish.

The code of the program is given below:

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

public class SayHelloToSpain extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
res.setHeader("Content-Language", "es");
Locale locale = new Locale("es", "");
DateFormat df = DateFormat.getDateTimeInstance
(DateFormat.LONG,DateFormat.LONG,locale);
df.setTimeZone(TimeZone.getDefault());
out.println("Hello spain will be written in this way");
out.println("En Espaņol:");
out.println("\u00a1Hola Mundo!");
out.println(df.format(new Date()));
}
}

The output of the program is given below:

 

Download this example.