제가 현재 하려는 것이 로그인인데요 아이디랑 비밀번호를 잘 입력을해서 디비랑 일치하면 서버에서 OK를 보내줍니다....저는 이걸 이용해서 ok를 받을 때만 화면전환을 하려고하는데 도와주세요 잘 안됩니다.ㅠㅠ
제가 onPostExecute 에서 intent를 쓰고있는데 저기서 하는것이 잘못된것인지 아니면 제가 비교를 잘못한건지 궁금합니다... 제발알려주세요 ㅠㅠ
12-07 16:01:02.185 23729-23827/com.example.admin.myapplication I/통신 결과: OK
class CustomTask extends AsyncTask<String, Void, String> {
String sendMsg;
@Override
protected String doInBackground(String... strings) {
try {
String str;
URL url = new URL("http://localhost:8080/JJUstubuilding_test/andlogin_pro.spring");//보낼 jsp 주소를 ""안에 작성합니다.
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("POST");//데이터를 POST 방식으로 전송합니다.
OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
sendMsg = "user_id="+strings[0]+"&user_pw="+strings[1];
osw.write(sendMsg);//OutputStreamWriter에 담아 전송합니다.
osw.flush();
//jsp와 통신이 정상적으로 되었을 때 할 코드들입니다.
if(conn.getResponseCode() == conn.HTTP_OK) {
InputStreamReader tmp = new InputStreamReader(conn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(tmp);
StringBuffer buffer = new StringBuffer();
//jsp에서 보낸 값을 받겠죠?
while ((str = reader.readLine()) != null) {
buffer.append(str);
}
receiveMsg = buffer.toString();
Log.i("통신 결과", receiveMsg);
} else {
Log.i("통신 결과", conn.getResponseCode()+"에러");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//jsp로부터 받은 리턴 값입니다.
return receiveMsg;
}
@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
if (result.trim() == "OK"){
Log.d("결과", "result = " + result);
Intent i = new Intent(getApplicationContext(), Main2Activity.class);
startActivity(i);
}else {
Toast.makeText(getApplicationContext(),"확인",Toast.LENGTH_LONG).show();
}
}
}