JohnneyAnn 2016-08-08 13:08 采纳率: 0%
浏览 1094
已结题

安卓访问tomcat抛出FileNotFoundException,显示出错的是获取dis的地方

开发新手,刚接触 望大家指点
代码段

new Thread() {
                    public void run() {
                        String httpURL = "http://115.159.118.230:8080/map/map";
                        URL url = null;
                        try {
                            url = new URL(httpURL);
                        } catch (MalformedURLException e1) {
                            e1.printStackTrace();
                        }
                        if (url != null) {
                            try {
                                HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                                conn.setRequestMethod("POST");
                                conn.setUseCaches(false);
                                conn.connect();
                                DataOutputStream dos = new DataOutputStream(
                                        conn.getOutputStream());
                                dos.writeInt(MyProtocal.LOGIN);
                                dos.writeInt(MyProtocal.ID_STUDENT);
                                dos.writeInt(Integer.parseInt(snoEditText.getText().toString()));
                                dos.writeUTF(pwdEditText.getText().toString());
                                dos.flush();
                                dos.close();
                                    //程序到这就不运行了
                                DataInputStream dis = new DataInputStream(conn.getInputStream());
                                Log.i("tag", "dis");
                                int b= dis.readInt();
                                if(b==MyProtocal.OK){
                                    Intent intent1 = new Intent(context, StudentMapActivity.class);
                                    startActivity(intent1);
                                }
                                dis.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(context, "url is null",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                }.start();  

Logcat:
08-08 20:51:47.454: W/System.err(8915): java.io.FileNotFoundException: http://115.159.118.230:8080/map/map
08-08 20:51:47.454: W/System.err(8915): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
08-08 20:51:47.454: W/System.err(8915): at com.hfuu.map_ts.LoginActivity$3.run(LoginActivity.java:187)

tomcat配置文件web.xml

<?xml version="1.0" encoding="utf-8"?>
            <web-app>
                        <servlet>
                                    <servlet-name>mapServ</servlet-name>
                                    <servlet-class>MapServerHttpServlet</servlet-class>
                        </servlet>

                        <servlet-mapping>
                                    <servlet-name>mapServ</servlet-name>
                                    <url-pattern>/map</url-pattern>
                        </servlet-mapping>

        </web-app>

登录时tomcat界面也没有打印出任何信息 没反应
希望大家帮忙!

  • 写回答

2条回答 默认 最新

  • wolf犭良 2016-08-09 16:01
    关注

    urlConnection.setDoOutput(true); // 发送POST请求必须设置,用以推送参数
    urlConnection.setDoInput(true); // 默认为true;
    打印下请求结果:urlConnection.getResponseCode(),确认访问是否成功,

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器