在JSP中从Android读取Http post参数

在JSP中从Android读取Http post参数,android,jsp,Android,Jsp,我正在制作一个应用程序,它应该向我的jsp发出post请求。我制作了所有用示例编写的东西,但它仍然不起作用。我在服务器上捕获请求,但所有参数返回null 安卓代码 HttpClient httpClient = new DefaultHttpClient(); HttpResponse response; String responseString = null; HttpPost httpPost = new HttpPost(uri); try { List<NameValu

我正在制作一个应用程序,它应该向我的jsp发出post请求。我制作了所有用示例编写的东西,但它仍然不起作用。我在服务器上捕获请求,但所有参数返回
null

安卓代码

HttpClient httpClient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
HttpPost httpPost = new HttpPost(uri);

try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("group", group));
    nameValuePairs.add(new BasicNameValuePair("increment", String.valueOf(additionalPoints)));
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    response = httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
HttpClient-HttpClient=newdefaulthttpclient();
HttpResponse响应;
字符串responseString=null;
HttpPost HttpPost=新的HttpPost(uri);
试一试{
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“组”,组));
添加(新的BasicNameValuePair(“增量”,String.valueOf(additionalPoints)));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
response=httpClient.execute(httpPost);
}捕获(客户端协议例外e){
}捕获(IOE异常){
}
JSP代码

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
    String group = request.getParameter("group");
    String incrementStr = request.getParameter("increment");
%>

我做错了什么?

像这样试试

Android代码

@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        try
        {
            setContentView(R.layout.main);
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(url);

            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            paris.add(new BasicNameValuePair("group", group));
            paris.add(new BasicNameValuePair("increment", String.valueOf(additionalPoints)));
            post.setEntity(new UrlEncodedFormEntity(pairs));
            HttpResponse response = client.execute(post);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
@覆盖
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
尝试
{
setContentView(R.layout.main);
HttpClient=new DefaultHttpClient();
HttpPost=新的HttpPost(url);
列表对=新的ArrayList();
添加(新的BasicNameValuePair(“集团”),集团);
add(新的BasicNameValuePair(“增量”,String.valueOf(additionalPoints)));
setEntity(新的UrlEncodedFormEntity(对));
HttpResponse response=client.execute(post);
}
捕获(例外e)
{
e、 printStackTrace();
}
}
JSP代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<%
    String group=request.getParameter("group");
    String increment=request.getParameter("increment");
%>

</html>


它还不能正常工作。参数为空。你的代码为你工作吗?不,我没有测试对不起…但我找到了这篇文章,我希望它能帮助你不,代码不会为他工作。他将有一个
NetworkOnMainThreadException
,因为该代码应该放在异步任务或线程中。和你的代码有什么不同呢???是的,我在
AsyncTask
中有它,我在服务器端得到了请求。唯一的问题是参数总是
null