package com.like.Biz;
import com.like.dao.checkDao;
import com.like.entity.User;
public class checkBiz {
public boolean checkUser(String userName){
return new checkDao().checkUser(userName);
}
}
servle处理代码
package com.like.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.like.Biz.LogRBiz;
import com.like.Biz.RegBiz;
import com.like.Biz.checkBiz;
import com.like.entity.User;
public class CheckServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public CheckServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GBK");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
checkBiz cb = new checkBiz();
String name = request.getParameter("userName");
String flag = request.getParameter("flag");
if (!"".equals(flag) && flag != null) {
// ajax 检查用户名是否存在
// User u = new User();
// u.setName(name);
boolean b = cb.checkUser(name);
out.print(b);
} else {
// 调用业务逻辑处理
User u = new User();
u.setName(name);
RegBiz rbiz = new RegBiz();
int n = rbiz.addUser(u);
// 根据结果转向
if (n > 0) {
request.setAttribute("u", u);
request.getRequestDispatcher("viewUser.jsp").forward(request,
response);
} else {
response.sendRedirect("register.jsp");
}
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}