想做一个无线点餐的安卓app 开桌把桌号传到数据库 但是servlet不太会 想请教为什么出错 这是activity传数据的主要代码 package com.systaresto_client; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import util.HttpUtil; import com.systaresto_client.R; import com.systaresto_client.R.layout; import com.systaresto_client.R.menu; import android.os.AsyncTask; import android.os.Bundle; import android.os.StrictMode; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; @SuppressLint("NewApi") public class KaizhuoActivity extends Activity { String personNum; String tableID; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kaizhuo); Button openTb = (Button)findViewById(R.id.openTbButton);//caidan openTb.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText personNumEt = (EditText) findViewById(R.id.personNumEditText02); personNum = personNumEt.getText().toString(); EditText tableIDEt = (EditText) findViewById(R.id.tableNumEditText); tableID = tableIDEt.getText().toString(); // 桌�?� if ( tableID.equals("1")){ showDialog("该桌已开"); } else { Intent intent = new Intent(); // 调用点菜方法 // 桌号 intent.setClass(KaizhuoActivity.this,JiacaiActivity.class); Bundle bundle = new Bundle(); bundle.putString("tableID",tableID); bundle.putString("personNum",personNum); intent.putExtras(bundle); startActivity(intent); List<BasicNameValuePair> params =new LinkedList<BasicNameValuePair>(); params.add(new BasicNameValuePair("OrderNum", tableID)); params.add(new BasicNameValuePair("Person",personNum)); UrlEncodedFormEntity entity1=null; try { entity1 = new UrlEncodedFormEntity(params,HTTP.UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // 请求服务器Servlet的url String url = HttpUtil.BASE_URL+"servlet/KaizhuoServlet"; // 获得HttpPost对象 HttpPost request = HttpUtil.getHttpPost(url); // 为请求设置参数 request.setEntity(entity1); // 获得返回结果 String result= HttpUtil.queryStringForPost(request); System.out.print(result); StrictMode .setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().detectDiskWrites() .detectNetwork() // or .detectAll() for all // detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() // 探测SQLite数据库操作 .penaltyLog() // 打印logcat .penaltyDeath().build()); finish(); } } }); Button mCancel = (Button)findViewById(R.id.fanhui); mCancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish();//这个是关键 } }); Button mainMenu = (Button)findViewById(R.id.zhucaidan); mainMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(KaizhuoActivity.this, MainActivity.class); startActivity(i); KaizhuoActivity.this.startActivity(i); KaizhuoActivity.this.finish(); } }); } private void showDialog(String msg){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(msg) .setCancelable(false) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }) .setPositiveButton("添菜", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EditText personNumEt = (EditText) findViewById(R.id.personNumEditText02); String personNum = personNumEt.getText().toString(); EditText tableIDEt = (EditText) findViewById(R.id.tableNumEditText); String tableID = tableIDEt.getText().toString(); Intent intent = new Intent(); // 调用点菜方法 // 桌号 intent.setClass(KaizhuoActivity.this,JiacaiActivity.class); Bundle bundle = new Bundle(); bundle.putString("personNum",personNum); bundle.putString("tableID",tableID); intent.putExtras(bundle); startActivity(intent); } }); AlertDialog alert = builder.create(); alert.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.kaizhuo, menu); return true; } }
这是servlet
package 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 dao.kaizhuoDao; import dao.impl.KaizhuoDaoImpl; import entity.kaizhuo; public class KaizhuoServlet extends HttpServlet { public KaizhuoServlet() { super(); } public void destroy(){ super.destroy(); } private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // 桌号 String OrderNum = request.getParameter("OrderNum"); // 人数 String Person = request.getParameter("Person"); // 获得DAO接口 kaizhuoDao dao = new KaizhuoDaoImpl(); // 实例化订单类 kaizhuo k = dao.check(OrderNum, Person); kaizhuo kz = new kaizhuo(); kz.setOrderNum(OrderNum); kz.setPerson(Person); // 设置订单属性 k.setPerson(Person); k.setOrderNum(OrderNum); dao.saveKaizhuo(kz); out.flush(); out.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } public void init() throws ServletException{ } }
开桌 dao
package dao; import entity.kaizhuo; public interface kaizhuoDao { // 开桌信息 public kaizhuo check (String OrderNum ,String Person ); public kaizhuo saveKaizhuo(kaizhuo kz); }
entity开桌
DBUtil
贴报错信息<divclass="ref">
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。