weixin_41342686
2019-04-29 19:53android studio连接不上tomacte?
1.myeclipae将项目部署在tomacate上,浏览器可以访问,Android模拟器访问不了,也不报错
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void loginClick(View v) {
String path = "http://10.0.2.2:8080/Demo1/Servlet1";
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(5000);
int code = connection.getResponseCode();
if (code == 200) {
Toast.makeText(getApplicationContext(),"成功",Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
}
}
}
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- android studio中用图片设置布局背景,图片不显示
- android-studio
- xml
- 2个回答
- 在Android Studio中,用jdbc连接MySQL连不上
- 数据库
- android-studio
- mysql
- jdbc
- 5个回答
- win10 64位安装Android studio检测不到JDK?
- android-studio
- java
- 4个回答
- 装完Android studio为什么启动不了模拟器?
- android-studio
- 2个回答
- android studio avd找不到应用图标
- android-studio
- avd
- android
- 3个回答
换一换