HttpServletResponse: setHeader(String name, String value) : HttpServletResponse « javax.servlet.http « Java by API






HttpServletResponse: setHeader(String name, String value)

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloSpain 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 fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    fmt.setTimeZone(TimeZone.getDefault());

    out.println("En Espa\u00f1ol:");
    out.println("\u00a1Hola Mundo!");
    out.println(fmt.format(new Date()));
  }
}

           
       








Related examples in the same category

1.HttpServletResponse: addCookie(Cookie arg0)
2.HttpServletResponse.SC_BAD_REQUEST
3.HttpServletResponse.SC_MOVED_TEMPORARILY
4.HttpServletResponse: encodeURL(String url)
5.HttpServletResponse: sendRedirect(String arg0)
6.HttpServletResponse: setContentType( text/html; charset=UTF-8 );
7.ServletResponse: setBufferSize(int arg0)
8.HttpServletResponse: setContentType("text/vnd.wap.wml")
9.HttpServletResponse: sendError(int arg0, String arg1)
10.HttpServletResponse: setHeader(String name, String value) (2)
11.HttpServletResponse: setStatus(int status)