private String sendData(String device, String os)
throws ClientProtocolException, IOException {
HttpPost request = makeHttpPost(device, os,
"http://xx.xx.xx/insert_device.jsp");
HttpClient client = new DefaultHttpClient();
ResponseHandler<String> reshandler = new BasicResponseHandler();
String result = client.execute(request, reshandler);
return result;
}
private HttpPost makeHttpPost(String device, String os, String url) {
HttpPost request = new HttpPost(url);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("deviceToken", device));
nameValuePairs.add(new BasicNameValuePair("os", os));
request.setEntity(makeEntity(nameValuePairs));
return request;
}
private HttpEntity makeEntity(ArrayList<NameValuePair> nameValue) {
HttpEntity result = null;
try {
result = new UrlEncodedFormEntity(nameValue);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
이거랑
public void HttpPostData() {
try {
// --------------------------
// URL 설정하고 접속하기
// --------------------------
URL url = new URL("
"http://xx.xx.xx/insert_device.jsp"); // URL
// 설정
HttpURLConnection http = (HttpURLConnection) url.openConnection(); // 접속
// --------------------------
// 전송 모드 설정 - 기본적인 설정이다
// --------------------------
http.setDefaultUseCaches(false);
http.setDoInput(true); // 서버에서 읽기 모드 지정
http.setDoOutput(true); // 서버로 쓰기 모드 지정
http.setRequestMethod("POST"); // 전송 방식은 POST
// 서버에게 웹에서 <Form>으로 값이 넘어온 것과 같은 방식으로 처리하라는 걸 알려준다
http.setRequestProperty("content-type",
"application/x-www-form-urlencoded");
// --------------------------
// 서버로 값 전송
// --------------------------
StringBuffer buffer = new StringBuffer();
buffer.append("deviceToken").append("=").append(registration)
.append("&"); // php 변수에 값 대입
buffer.append("os").append("=").append("android");
OutputStreamWriter outStream = new OutputStreamWriter(
http.getOutputStream(), "EUC-KR");
PrintWriter writer = new PrintWriter(outStream);
writer.write(buffer.toString());
writer.flush();
//--------------------------
// 서버에서 전송받기
//--------------------------
InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "EUC-KR");
BufferedReader reader = new BufferedReader(tmp);
StringBuilder builder = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) { // 서버에서 라인단위로 보내줄 것이므로 라인단위로 읽는다
builder.append(str + "\n"); // View에 표시하기 위해 라인 구분자 추가
}
} catch (MalformedURLException e) {
Log.e("error", e.getMessage().toString());
} catch (IOException e) {
Log.e("error", e.getMessage().toString());
} // try
} // HttpPostData
이거랑 둘다 써봣는데;; 둘다 안되네요;;
어플에서 http post로 jsp서버에 값들 전송하는건 어떻게 해야할까요?




상기 링크를 참고하시면 매우 도움이 되실 것 같습니다. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html
저의 경우 httpClient로 안드로이드 클라이언트에서 httpPost와 Get으로 서버에 데이터 전송을 하고
서버에서는 servlet으로 받아서 처리하였습니다. 서블릿이나 jsp나 별 다를바는 없지 않나요? :)