Service服务端代码(doPost请求)

<span style="font-size:18px;">package com.lrk.login.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lrk.login.jdbcdao.UsertableDao;
import com.lrk.login.jdbcdao.impl.UsertableImp;
import com.lrk.login.person.Person;
/**
 * 服务端代码:用于客户端注册时使用
 * @author kevin
 *
 */
public class RegestServer extends HttpServlet{
	/**
	 * doPost请求方式
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//设置请求的编码格式
		req.setCharacterEncoding("utf-8");
		//获得客户端请求的数据
		String name = req.getParameter("name");
		String password = req.getParameter("password");
		
		//将数据封装成对象
		Person person = new Person();
		person.setName(name);
		person.setPassword(password);
		
		//将数据传送给数据库
		UsertableDao utb = new UsertableImp();
		int i = utb.regist(person);
		//通过数据库返回的值判断注册状态
		if(i > 0){
			//响应客户端(回传数据给客户端)
			resp.getOutputStream().print(true);
		}else{
			//响应客户端(回传数据给客户端)
			resp.getOutputStream().print(false);
		}
		System.out.println("RegestServer:"+i);
	}
}
</span>

你可能感兴趣的:(Service服务端代码(doPost请求))