/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//Step one
System.out.println(new Date()+"\n");
InputStream sin = new BufferedInputStream(request.getInputStream());
ByteArrayOutputStream sout = new ByteArrayOutputStream();
int b=0;
while((b=sin.read())!=-1)
{
sout.write(b);
}
byte[] temp = sout.toByteArray();
String s_ok = new String(temp,"UTF-8");
String regex="[0123456789.]+"; //正则表达式分离s_ok
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(s_ok);
int i=0;
while(m.find())
{
String item=m.group();
System.out.println(item);
i++;
if(i==2)
{
id=Integer.parseInt(item);
System.out.println("这是第"+i+"个数字:"+item);
}
if(i==4)
{
time=item;
System.out.println("这是第"+i+"个数字:"+item);
}
if(i==6)
{
value=Integer.parseInt(item);
System.out.println("这是第"+i+"个数字:"+item);
}
}
System.out.println(s_ok);
String sql = null;
//System.out.print("this is request: "+request+"this is response: "+response);
System.out.println("id:"+id+",time: "+time+" ,value: "+value);
sql = "insert into location" //sql语句
+"(id,time,value)"
+"values( "+" ' "+id+" ' "+", "+" ' "+time+" ' "+", "+" ' "+value+" ' "+")";
DBHelper mysql = new DBHelper(sql);
try {
mysql.insertMess(request, id, time, value);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("未成功插入数据!_API");
}
}
return;
//doGet(request, response);
}