分类: 系统运维
2008-04-07 15:12:15
其中register.html的ajax部分可以做为一般的AJAX开发框架应用。
==========register.html==========
==========EComBaseInfo.java==========
package ajax;
public class EComBaseInfo {
String user;
String com;
public String getCom() {
return com;
}
public void setCom(String com) {
this.com = com;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public boolean findUser(String Ruser){
if(Ruser.equals("ghost")){
return true;
}else{
return false;
}
}
public boolean findCom(String Rcom){
if(Rcom.equals("guoguo")){
return true;
}else{
return false;
}
}
}
==========CheckUserAndCom.java==========
package ajax;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ajax.EComBaseInfo;
public class CheckUserAndCom extends HttpServlet {
private String msgStr = "";
String url = "";
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
EComBaseInfo info = new EComBaseInfo();
String oprate = request.getParameter("oprate").trim();
String userName = request.getParameter("userName");
String passWord = request.getParameter("password");
String comName = request.getParameter("comName");
try {
if (oprate.equals("chkUser")) {
response.setContentType("text/html;charset=utf-8");
if (userName.length() < 5 || userName.length() > 20) {
msgStr = "对不起,用户名必须为字母、数字或下划线,长度为5-20个字符!";
} else {
boolean bTmp = info.findUser(userName); // 找查数据库中有无该用户名
if (bTmp)
msgStr = "对不起,此用户名已经存在,请更换用户名注册!";
else
msgStr = "";
}
response.getWriter().write(msgStr);
} else if (oprate.equals("chkCom")){
response.setContentType("text/html;charset=utf-8");
if (comName.length() < 6 || comName.length() > 100) {
msgStr = "对不起,公司名称长度为6-100个字符(不包括字符内的空格)!";
} else {
boolean bTmp = info.findCom(comName); // 找查数据库中有无该企业名
if (bTmp)
msgStr = "对不起,此企业名称已经存在,请更换企业名称注册!";
else
msgStr = "";
}
response.getWriter().write(msgStr);
}
} catch (Exception ex) {
} finally {
request.setAttribute("url", url);
}
}
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
doGet(request, response);
}
}