<%--List8_2_1.jsp--%>
<%@ page import="java.util.prefs.BackingStoreException,
                 java.util.prefs.Preferences"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>访问注册表</title></head>
  <body>
  <%
      String items[] = {"Item1", "Item2", "Item3"};
      String values[] = {"Value 1", "Value 2", "Value 3"};
      //创建/com/foo/bar节点
      Preferences prefs = Preferences.userRoot().node("/com/foo/bar");
      //用put方法写健值对到注册表
      for (int i = 0; i < items.length; i++) {
          prefs.put(items[i], values[i]);
      }
      //使用get方法读取注册表中的值，并输出到控制台上
      try {
          String keys[] = prefs.keys();
          for (int i = 0, n = keys.length; i < n; i++) {
              System.out.println(keys[i] + ": " +
                      prefs.get(keys[i], "NULL"));
          }
      } catch (BackingStoreException e) {
          e.printStackTrace();
      }

      // 如果要看到注册表中的变化,请将下面的代码注释.
      try {
          prefs.removeNode();
      } catch (BackingStoreException e) {
          e.printStackTrace();
      }
      }
  %>
  </body>
</html>