java xml配合实现读取配置文件登陆

package com.fenung.summery;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class systemofuserloading {

	public static void main(String[] args) throws Exception {
		/**
		 * 通过键盘获得用户输入的账号和密码
		 */
		while (true) {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("请输入账号");
			String username = br.readLine();
			System.out.println("请输入密码");
			String password = br.readLine();

			/**
			 * 去数据库中查询是否有该用户名和密码
			 * 
			 */
			Document doc = new SAXReader().read(new File("./conf/user.xml"));

			Element userElem = (Element) doc
					.selectSingleNode("//user[@name='" + username + "' and @password='" + password + "']");

			if (userElem != null) {
				// 登录成功
				System.out.println("登录成功");
				break;
			} else {
				// 登录失败
				System.out.println("登录失败");
			}

		}
	}

}

你可能感兴趣的:(java)