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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: say hello in spanish View All Comments
Post your Comment