Java网络编程(模拟浏览器访问Tomcat服务器)
2016-03-28 10:49
671 查看
程序运行结果:
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1026
Date: Mon, 28 Mar 2016 02:45:16 GMT
Connection: close
目前位置还没有找到解决方法,我的html文件确实存在于这个路径下,但就是找不到,
问题已经解决:我把out.println("GET /myweb/index.html HTTP/1.1");这一行改成了out.println("GET /index.jsp HTTP/1.1");
index.jsp是我从webapps目录下拷贝过来的文件,去除了/myweb,Get请求默认的就是/webapps/index.jsp
运行结果:
忘了贴运行结果了:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 28 Mar 2016 02:59:13 GMT
Connection: close
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1026
Date: Mon, 28 Mar 2016 02:45:16 GMT
Connection: close
目前位置还没有找到解决方法,我的html文件确实存在于这个路径下,但就是找不到,
package WebProgramingDemo; import java.io.InputStream; import java.io.PrintStream; import java.net.Socket; import java.net.UnknownHostException; public class MyBrowser { /** * @param args * @throws Exception * @throws UnknownHostException */ // 模拟一个浏览器来获取服务器信息 public static void main(String[] args) throws Exception { Socket s = new Socket("192.168.2.103", 8080); PrintStream out = new PrintStream(s.getOutputStream()); out.println("GET /myweb/index.html HTTP/1.1"); out.println("Accept: */*"); out.println("Host: 192.168.2.103:8888"); out.println("Connection: close"); out.println(); out.println(); InputStream in = s.getInputStream(); byte[] buf = new byte[1024]; int len = in.read(buf); System.out.println(new String(buf, 0, len)); } }
问题已经解决:我把out.println("GET /myweb/index.html HTTP/1.1");这一行改成了out.println("GET /index.jsp HTTP/1.1");
index.jsp是我从webapps目录下拷贝过来的文件,去除了/myweb,Get请求默认的就是/webapps/index.jsp
运行结果:
忘了贴运行结果了:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 28 Mar 2016 02:59:13 GMT
Connection: close
相关文章推荐
- 在与SQL Server建立连接时出现与网络相关的或特定于实例的错误
- iptraf:一个实用的TCP/UDP网络监控工具
- Linux网络编程--使用epoll,共享内存技术实现高性能的聊天室程序
- tcp/ip--IP 协议首部格式与其配套使用的四个协议(ARP,RARP,ICMP,IGMP)
- SpringMVC整合Shiro(原文:http://my.oschina.net/miger/blog/283526)
- tomcat6.0发布项目打开jsp页面报错:HTTP Status 500 - org.apache.jasper.JasperException: The absolute uri: http:/
- 决策森林和卷积神经网络二道归一
- 《LwIP协议栈源码详解——TCP/IP协议的实现》移植综述
- swift 网络搜索热词排行
- NFC会员管理-转载自http://technews.cn/2014/09/13/nfc-sticker/
- 第1章 基本网络概念
- httpd服务停止自动发送告警邮件
- android-async-http开源框架【转】
- 毕业论文-学生网络考试系统 (学生在线考试系统)(共享版)
- 基于网络流量的计费系统设计与实现
- 详解HTTPS中数字证书验证系统
- HTTPS简述
- OpenCV进阶之路:神经网络识别车牌字符
- 针对TQ部分ARM开发板中QTCPServer不能接受数据的问题
- 带上下界网络流小练(Bzoj2502&&Bzoj2055&&Bzoj3698)