package com.server.control;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.server.dao.Dao;
import com.server.dao.Infomation;
public class ControlServlet extends HttpServlet {
/**
*
*/
public ControlServlet(){
super();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
Dao dao=new Dao();
HttpSession ses=request.getSession();
String Name=request.getParameter("Name");
String Password=request.getParameter("Password");
String code=request.getParameter("code");
// System.out.println("...................Name="+Name+"..p."+Password+"..c..."+code);
response.setContentType("text/xml") ;
response.setCharacterEncoding("UTF-8") ;
PrintWriter out = response.getWriter();
try{
Password=MD5HashUtil.hashCode(Password);
}catch(Exception e){
e.printStackTrace();
return;
}
out.println("<?xml version='1.0' encoding='utf-8'?>");
if(code.equals(ses.getAttribute("code").toString().replaceAll(" ",""))==false){
out.print("<Package>");
out.print("<Message> 验证码错误");
out.print("</Message>");
out.print("</Package>");
out.close();
}else{
String guid=dao.ValidateUser(Name,Password);
if(guid!=null){
List<Infomation> list=dao.SerarchInfoMation(guid);
if(list!=null&&list.size()>0){
out.print("<Package>");
for(Infomation in:list){
out.print("<Server>");
System.out.println("................."+in.getServerName()+"..."+in.getIp()+"..."+in.getPort()+".."+in.getGuid());
out.print("<ServerName>"+in.getServerName());
out.print("</ServerName>");
out.print("<Ip>"+in.getIp());
out.print("</Ip>");
out.print("<Port>"+in.getPort());
out.print("</Port>");
out.print("<Guid>"+in.getGuid());
out.print("</Guid>");
out.print("<Flag>"+in.getFlag());
out.print("</Flag>");
out.print("</Server>");
}
out.print("</Package>");
out.close();
}else{
out.print("<Package>");
out.print("<Message> 没有找到账户");
out.print("</Message>");
out.print("</Package>");
out.close();
}
}else{
out.print("<Package>");
out.print("<Message>账户或者密码不正确");
out.print("</Message>");
out.print("</Package>");
out.close();
}
}
}
}