마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 (jsp)웹서버간 통신질문드립니다

0 추천

안녕하세요 안드로이드 진로를 목표를 잡고 공부하고있는 대학생입니다 .

제가 안드로이드에서  jsp웹서버에 있는 글 내용이나 이미지 파일을 가져오고 싶은데 어떻게 접근 해야 될까요? 

html 코드가 아닌 글 내용 이나 이미지 파일 가져올수있는 예제나 강의가 있으면 추천해주세요 

(현재 jsp웹서버 html 코드를 안드로이드  텍스트뷰에 가져왔습니다)

 

아래는 코드입니다 . 

 

protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     //listView = (ListView) findViewById(R.id.list_view);
     textView=(TextView)findViewById(R.id.textview);
     String url="http://220.127.231.139:8080/db/showDaiog.jsp?id=8";
     myThread myThread=new myThread();
     myThread.start();

 }

class myThread extends Thread
{
    public void run()
    {
        try
        {
            URL url=new URL("http://14.47.218.96:8080/db/nemotest.jsp");
            HttpURLConnection conn=(HttpURLConnection)url.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setConnectTimeout(10000);
            if(conn.getResponseCode()==HttpURLConnection.HTTP_OK)
            {
               
                StringBuilder builder=new StringBuilder();
                BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));

                String line="";
                while(true)
                {
                    line=reader.readLine();

                    if(line ==null)
                    {
                        break;
                    }
                    builder.append(line +"/n");

                }
                reader.close();
                conn.disconnect();
                String output=builder.toString();
                println(output) ;
                
            }
            else
            {
                textView.setText(conn.getResponseCode());
            }


        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
}
private void println(final String output)
{
     handler.post(new Runnable() {
         @Override
         public void run() {
             textView.append(output+"/n");
         }
     });
}

 

kane9529 (1,110 포인트) 님이 2019년 5월 6일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...