01 package interval;
02
03 import javax.servlet.*;
04 import javax.servlet.http.*;
05 import java.io.*;
06 import java.util.*;
07 import java.text.DateFormat;
08
09 public class LocalizedServlet extends HttpServlet {
10
11
12 private static final String CONTENT_TYPE = "text/html; charset=windows-1250";
13
14 //Initialize global variables
15 public void init() throws ServletException {
16 }
17 //Process the HTTP Get request
18 public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
19
20 String param = req.getParameter("lang");
21 String lang = param.substring(0,2).trim();
22 String country = param.substring(3).trim();
23
24 ResourceBundle lres = ResourceBundle.getBundle("interval.ListResource", new Locale(lang,country));
25 ResourceBundle pres = ResourceBundle.getBundle("interval.PropertyResource", new Locale(lang,country));
26 DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, new Locale(lang,country));
27 String dnes = df.format(new Date());
28
29 res.setContentType(CONTENT_TYPE);
30 PrintWriter out = res.getWriter();
31 out.println("<html>");
32 out.println("<head><title>LocalizedServlet</title></head>");
33 out.println("<body bgcolor=\"#ffffff\">");
34 out.println(lres.getString("welcome"));
35 out.println(pres.getString("today") + " " + dnes);
36 out.println("<a href='choose.jsp'>"+ lres.getString("back") + "</a>");
37 out.println("</body></html>");
38 }
39 //Clean up resources
40 public void destroy() {
41 }
42 }
|