Handling Localized Input

So far we have discussed only how to generate pages in different languages, but most applications also need to deal with localized input. As long as you’re supporting only western European languages, the only thing you typically need to worry about is how to interpret dates and numbers. The LocaleBean introduced in the previous section can help with this.

Example 11.5 shows a JSP page with the same form for selecting a language as you saw in Example 11.1, plus a form with one field for a date and another for a number.

Example 11-5. Date and Number Input Form (input.jsp)

<%@ page language="java" contentType="text/html" %>
<%@ page import="java.util.*" %>
<%@ taglib uri="/orataglib" prefix="ora" %><ora:useLocaleBundle id="locale" bundleName="input" 
  supportedLangs="en, sv, de" />

<html>
  <head>
    <title>
      <ora:getLocalText name="locale" key="input.title" />
    </title>
  </head>
  <body bgcolor="white">
    <h1>
      <ora:getLocalText name="locale" key="input.title" />
    </h1>

    <ora:getLocalText name="locale" key="input.select_language" />:
    <form action="input.jsp">
      <p>
      <input type="radio" name="language" value="en"
        <%= locale.getLanguage( ).equals("en") ? "checked" : "" %>>
        <%= locale.getText("input.english") %><br>
      <input type="radio" name="language" value="sv"
        <%= locale.getLanguage( ).equals("sv") ? "checked" : "" %>>
        <%= locale.getText("input.swedish") %><br>
      <input type="radio" name="language" value="de"
        <%= locale.getLanguage( ).equals("de") ? "checked" : "" %>>
        <%= locale.getText("input.german") ...

Get Java Server Pages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.