public class Validator
{
public boolean isValid(String name, String pw)
{
                 String userName = "";
                 String password = "";
try 
{
DOMParser parser = new DOMParser();
parser.parse("这里输入xml文件所在的完整路径");
Document document = parser.getDocument();
NodeList userList = document.getElementsByTagName("用户名");
                        Node user = userList.item(0);
                        userName = user.getFirstChild().getNodeValue();
                        NodeList pwList = document.getElementByTagName("密码");
                        password = pw.Item(0).getFirstChild().getNodeValue();
}
catch (IOException io)
{
io.printStackTrace();
}
catch (SAXException saxe)
{
saxe.printStackTrace();
}
     if(name.equals(userName) && pw.equals(password))
     {
          return true;
      }else{
          return false;
      }
}
}
在页面中调用如下:String userName = request.getParameter("userName");
String password = request.getParameter("password");
Validator val = new Validator();
boolean volid = val.valid(userName, password);
if(volid)
{
     response.sendRedirect(String destUrl);
}
else
{
     response.sendRedirect(String oriUrl);
}