android:usesCleartextTraffic="true"
http://tomcat.apache.org/
다운로드 후 압축 풀고 로컬 디스크 (C:)로 이동
-> 서버 실행은 bin 폴더에서
cmd 열고 'cd bin폴더경로' enter
'startup' enter
http://localhost:8080/
냥이 뜨면 성공
📌 설정 > 시스템 > 정보 > 고급 시스템 설정 > JAVA_HOME 환경 변수 설정 필수
필요한 파일들 다 ROOT 폴더안에 넣기
<application
...
android:usesCleartextTraffic="true">
</application>
...
<uses-permission android:name="android.permission.INTERNET"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="서버 접속" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</LinearLayout>
package com.example.httpnetwork
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.httpnetwork.databinding.ActivityMainBinding
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import kotlin.concurrent.thread
class MainActivity : AppCompatActivity() {
private var _binding: ActivityMainBinding? = null
private val binding get() = _binding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
_binding = ActivityMainBinding.inflate(layoutInflater)
binding.button.setOnClickListener {
thread {
// 접속할 주소
val site = "http://172.30.1.47:8080/basic.jsp"
val url = URL(site)
// 접속
val conn = url.openConnection() as HttpURLConnection
val isr = InputStreamReader(conn.inputStream, "UTF-8")
val br = BufferedReader(isr)
var str: String? = null
val buf = StringBuffer()
do {
str = br.readLine()
if (str != null) {
buf.append("$str/n")
}
} while (str != null)
runOnUiThread {
binding.textView.text = buf.toString()
}
}
}
}
}