Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从android接收数据?_Android_Json_Servlets - Fatal编程技术网

无法从android接收数据?

无法从android接收数据?,android,json,servlets,Android,Json,Servlets,我的servlet没有从android客户端接收数据。日志中不显示错误或警告。我的android屏幕以html格式显示类似tomcat错误报告的内容。如何在servlet中从android检索数据。我的servlet返回null。如何检查我的servlet是否接收数据 public boolean PostData() { try { String URL = "http://10.0.2.2:8080/myapp/StudentDetails"; boolean isPos

我的servlet没有从android客户端接收数据。日志中不显示错误或警告。我的android屏幕以html格式显示类似tomcat错误报告的内容。如何在servlet中从android检索数据。我的servlet返回null。如何检查我的servlet是否接收数据

public boolean PostData() 
{
try {
    String URL = "http://10.0.2.2:8080/myapp/StudentDetails"; 
    boolean isPosted;
    String name = getIntent().getExtras().getString("name");
    String classs = getIntent().getExtras().getString("classs");
    String age = getIntent().getExtras().getString("age");

    // creating default Client 
    HttpClient mClient = new DefaultHttpClient();
    // Connect URL 
    StringBuilder sb=new StringBuilder(URL);
    HttpPost mpost = new HttpPost(sb.toString());
    List<BasicNameValuePair> nameValuepairs = new ArrayList<BasicNameValuePair>(3);
    nameValuepairs.add(new BasicNameValuePair("name",name));
    nameValuepairs.add(new BasicNameValuePair("classs",classs));
    nameValuepairs.add(new BasicNameValuePair("age",age));
    mpost.setEntity(new UrlEncodedFormEntity(nameValuepairs));
    HttpResponse responce = mClient.execute(mpost);
    HttpEntity entity = responce.getEntity();
    BufferedReader buf = new BufferedReader(new  InputStreamReader(entity.getContent()));
    StringBuilder sb1 = new StringBuilder();
    String line = null;
    while ((line = buf.readLine()) != null) {
    sb1.append(line+"\n");
    }
    Toast.makeText(getApplicationContext(), sb1.toString()+"",1).show();
    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setText(sb1.toString());

    isPosted = true;
    } catch (UnsupportedEncodingException e) {
    Log.w(" error ", e.toString());
    } catch (Exception e) {
    Log.w(" error ", e.toString());
    }
    return false ;
    }
Servlet编码

您是否在清单中指定了INTERNET权限?
     public class ClassDetails extends HttpServlet {

/**
 * 
 */
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request,
        HttpServletResponse response)
     throws ServletException, IOException
    {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Database Result";
    String docType =  "<!doctype html public \"-//w3c//dtd html 4.0 "  +"transitional//en\">\n";
    out.println(docType + "<html>\n" + "<head><title>" + title + "</title> </head>\n" + "<body bgcolor=\"#f0f0f0\">\n" +  "<h1 align=\"center\">" + title + " </h1>\n");

   String name = request.getParameter("name");
   String classs = request.getParameter("classs");
   String age = request.getParameter("age");
   if(sldept !=null)
   {
       out.println(" First: " + name + "<br>");
       out.println(" Last: " + classs + "<br>");
       out.println(" Last: " + age + "<br>");

   }
   else
   {
       out.println("no value");

      }   
    }
      }