- 浏览: 459616 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (272)
- java基础 (59)
- struts (8)
- spring (8)
- 数据库 (8)
- java 网络编程 (29)
- hibernate (3)
- JavaScript (10)
- 日志管理 (2)
- jsp (4)
- servlet (7)
- xml (4)
- ajax (2)
- web service (4)
- 算法与数据结构 (13)
- java 反射机制 (11)
- java 泛型 (3)
- java I/O (8)
- java 线程 (12)
- JavaEE (6)
- java解惑 (33)
- 工具 (5)
- MyEclipse编程实践 (1)
- OSGI (2)
- 设计模式 (9)
- 正则表达式 (0)
- EJB (3)
- Ubuntu linux (6)
- Android (1)
- web前端 (2)
- 找工作 (1)
- SCA (1)
- maven (1)
- 缓存 (1)
- json (1)
- javamail (1)
- 工作笔记 (2)
最新评论
-
霜花似雪:
博主可以分享一下源码吗?
使用maven构建web项目实例 -
王庆波-行:
很好的demo!
memcache使用实例 -
surpassno:
大写的牛逼
java可视化显示内存使用情况 -
zhulin0504:
怎么访问NetEcho.html页面呀???
applet与servlet的网络通信 -
springdata:
java多线程实例demo源代码下载:http://www.z ...
java多线程例子
本例向用户通过参数指定的主机端口发送一段请求报文,然后读取和打印反馈报文。综合应用了NIO的缓冲区,通道和字符集。使用到了Tomcat服务器 参数为localhost 8080
运行后结果
该html对应的是Tomcat的主页
第五章所有源码见附件
package nio; import java.io.IOException; import java.net.UnknownHostException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; public class ReadURL { public static void main(String args[]) { String host = args[0]; int port = Integer.parseInt(args[1]); SocketChannel channel = null; //所有输入输出通过通道这个对象 try { // Setup InetSocketAddress socketAddress = new InetSocketAddress(host, port);// Charset charset = Charset.forName("UTF-8"); CharsetDecoder decoder = charset.newDecoder(); CharsetEncoder encoder = charset.newEncoder(); // Allocate buffers ByteBuffer buffer = ByteBuffer.allocateDirect(1024); CharBuffer charBuffer = CharBuffer.allocate(1024); // Connect channel = SocketChannel.open(); channel.connect(socketAddress); // Send request String request = "GET / \r\n\r\n"; channel.write(encoder.encode(CharBuffer.wrap(request))); // Read response while ((channel.read(buffer)) != -1) { buffer.flip(); // Decode buffer decoder.decode(buffer, charBuffer, false); // Display charBuffer.flip(); System.out.println(charBuffer); buffer.clear(); charBuffer.clear(); } } catch (UnknownHostException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } finally { if (channel != null) { try { channel.close(); } catch (IOException ignored) { } } } } }
运行后结果
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lan g="en"> <head> <title>Apache Tomcat</title> <style type="text/css"> /*<![CDATA[*/ body { color: #000000; background-color: #FFFFFF; font-family: Arial, "Times New Roman", Times, serif; margin: 10px 0px; } img { border: none; } a:link, a:visited { color: blue } th { font-family: Verdana, "Times New Roman", Times, serif; font-size: 110%; font-weight: normal; font-style: italic; background: #D2A41C; text-align: left; } td { color: #000000; font-family: Arial, Helvetica, sans-serif; } td.menu { background: #FFDC75; } .center { text-align: center; } .code { color: #000000; font-family: "Courier New", Courier, monospace; font-size: 110%; margin-left: 2.5em; } #banner { margin-bottom: 12px; } p#congrats { margin-top: 0; font-weight: bold; text-align: center; } p#footer { text-align: right; font-size: 80%; } /*]]>*/ </style> </head> <body> <!-- Header --> <table id="banner" width="100%"> <tr> <td align="left" style="width:130px"> <a href="http://tomcat.apache.org/"> <img src="tomcat.gif" height="92" width="130" alt="The Mighty Tomcat - MEOW!"/> </a> </td> <td align="left" valign="top"><b>Apache Tomcat</b></td> <td align="right"> <a href="http://www.apache.org/"> <img src="asf-logo-wide.gif" height="51" width="537" alt="The Apache Software Foundation"/> </a> </td> </tr> </table> <table> <tr> <!-- Table of Contents --> <td valign="top"> <table width="100%" border="1" cellspacing="0" cellpadding="3"> <tr> <th>Administration</th> </tr> <tr> <td class="menu"> <a href="manager/status">Status</a><br/> <!--<a href="admin">Tomcat Administration</a><br/>--> <a href="manager/html">Tomcat Manager</a><br/> </td> </tr> </table> <br /> <table width="100%" border="1" cellspacing="0" cellpadding="3"> <tr> <th>Documentation</th> </tr> <tr> <td class="menu"> <a href="RELEASE-NOTES.txt">Release Notes</a><br/> <a href="docs/changelog.html">Change Log</a><br/> <a href="docs">Tomcat Documentation</a><br/> </td> </tr> </table> <br/> <table width="100%" border="1" cellspacing="0" cellpadding="3"> <tr> <th>Tomcat Online</th> </tr> <tr> <td class="menu"> <a href="http://tomcat.apache.org/">Home Page</a><br/> <a href="http://tomcat.apache.org/faq/">FAQ</a><br/> < a href="http://tomcat.apache.org/bugreport.html">Bug Database</a><br/> <a href="http://issues.apache.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=RESOLVED&resolution=LATER&resolution=REMIND&resolution=---&bugidtype=include&product=Tomcat+6&cmdtype=doit&order=Importance">Open Bugs</a><br/> <a href="http://mail-archives.apache.org/mod_mbox/tomcat-users/">Users Mailing List</a><br/> <a href="http://mail-archives.apache.org/mod_mbox/tomcat-dev/">Developers Mailing List</a><br/> <a href="irc://irc.freenode.net/#tomcat">IRC</a><br/> </td> </tr> </table> <br/> <table width="100%" border="1" cellspacing="0" cellpadding="3"> <tr> <th>Miscellaneous</th> </tr> <tr> <td class="menu"> <a href="examples/servlets/">Servlets Examples</a><br/> <a href="examples/jsp/">JSP Examples</a><br/> <a href="http://java.sun.com/products/jsp">Sun's Java Server Pages Site</a><br/> <a href="http://java.sun.com/products/servlet">Sun's Servlet Site</a><br/> </td> </tr> </table> </td> <td style="width:20px"> </td> <!-- Body --> <td align="left" valign="top"> <p id="congrats">If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!</p> <p>As you may have guessed by now, this is the default Tomcat home page. It can be found on the local filesystem at:</p> <p class="code">$CATALINA_HOME/webapps/ROOT/index.html</p> <p>where "$CATALINA_HOME" is the root of the Tomcat installation directory. If you're seeing this page, and you don't think you should be, then you're either a user who has arrived at new installation of Tomcat, or you're an administrator who hasn't got his/her setup quite right. Providing the latter is the case, please refer to the <a href="docs">Tomcat Documentation</a> for more detailed setup and administration information than is found in the INSTALL file.</p> <p><b>NOTE: For security reasons, using the administration webapp is restricted to users with role "admin". The manager webapp is restricted to users with role "manager".</b> Users are defined in <code>$CATALINA_HOME/conf/tomcat-users.xml</code>.</p> <p>Included with this release are a host of sample Servlets and JSPs (with associated source code), extensive documentation, and an introductory guide to developing web applications.</p> <p>Tomcat mailing lists are available at the Tomcat project w eb site:</p> <ul> <li><b><a href="mailto:users@tomcat.apache.org">users@tomcat.apache.org</a></b> for general questions related to configuring and using Tomcat</li> <li><b><a href="mailto:dev@tomcat.apache.org">dev@tomcat.apache.org</a></b> for developers working on Tomcat</li> </ul> <p>Thanks for using Tomcat!</p> <p id="footer"><img src="tomcat-power.gif" width="77" height="80" alt="Powered by Tomcat"/><br/> Copyright © 1999-2007 Apache Software Foundation<br/> All Rights Reserved </p> </td> </tr> </table> </body> </html>
该html对应的是Tomcat的主页
第五章所有源码见附件
- ch05.rar (17.1 KB)
- 下载次数: 1
发表评论
-
计算机网络知识
2011-06-01 16:19 766一个http请求的详细过程 我们来看当我们在浏览器输入htt ... -
java udp socket实例
2010-12-06 12:28 7093客户端: package udp; import jav ... -
线程池实现tcp socket
2010-12-01 17:23 2849前面的程序,当一个客户端请求到来时,服务器端就会临时性的创建一 ... -
tcp socket实例(改进)
2010-12-01 16:16 1569上一篇的程序服务器端只能接受一个客户端请求,本篇改为模拟多客户 ... -
java tcp socket实例
2010-12-01 13:44 1598网络编程的基本模型就是客户端到服务器端模型,一段必须提供一个固 ... -
telnet协议(转)
2010-10-14 17:17 1114我们知道Telnet服务器软 ... -
whois协议(转)
2010-10-14 14:28 1336当我们预备建立一个Web站点,就必须向域名登记机构申请一个In ... -
java 网络协议(一)Tcp多线程服务器端编程
2010-10-14 11:33 54611,通用服务器代码: package multiThread; ... -
java 网络协议(一)UDP
2010-10-14 09:24 1438UDP测试程序,无需建立连接 package udp; ... -
java 网络协议(一)Tcp
2010-10-14 08:52 51081,简化的服务器端程序 package tcp; imp ... -
java 网络协议(一)InetAddress和Socket(含源码)
2010-10-14 08:24 18581,ip地址和主机名互换 package getip; ... -
ftp协议2(转)
2010-10-12 16:26 940FTP协议工作原理 FTP有 ... -
ftp协议(转)
2010-10-12 16:21 1237ftp协议 FTP协议将使用两 ... -
SMTP服务协议(转)
2010-10-11 15:31 1214SMTP服务概述 鉴于本课程的默认读者群是那些对Inter ... -
利用socket发送接收邮件(转)
2010-10-11 15:18 4155这是在网上摘的,执行接收邮件出现:530 Authentica ... -
jdk6.0从入门到精通-----chapter6--http
2010-09-14 16:32 913用httpconnection进行文件下载,建立一般的jav ... -
java自学===Filter类的应用,验证用户
2010-09-14 14:37 911Filter类 package com; import ... -
java自学===Filter类的应用,网站数量统计
2010-09-14 12:31 1911package filterStatistic; imp ... -
jdk6.0从入门到精通-----chapter5网络编程 udp套接字
2010-09-12 13:46 1132用到的主要类DatagramPacket,DatagramSo ... -
jdk6.0从入门到精通-----chapter5网络编程 tcp连接池
2010-09-10 18:07 959package pool; import java.ne ...
相关推荐
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/765024
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/759473
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/758765
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/759635
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/759558
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/765052
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/764901
微信开发平台开发工具 JDK jdk 6.0 jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008
开发工具 jdk-8u121-windows-i586开发工具 jdk-8u121-windows-i586开发工具 jdk-8u121-windows-i586开发工具 jdk-8u121-windows-i586开发工具 jdk-8u121-windows-i586开发工具 jdk-8u121-windows-i586开发工具 jdk-8...
java6.0文档chm版,分成三部分,分别为JDK6.0+中文文档-lytim24.part1.rar、JDK6.0+中文文档-lytim24.part2.rar、JDK6.0+中文文档-lytim24.part3.rar
jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows-i586,jdk-6u39-windows...
jdk-8u60-windows-i586 jdk-8u60-windows-i586 jdk-8u60-windows-i586 jdk-8u60-windows-i586 jdk-8u60-windows-i586
java-jdk1.8-8u361-all-jdk-win-linux 该压缩包中包含jdk1.8-8u361下windows版本和linux版本,其包含快速安装包和对应的jdk压缩包版本,具体内容如下: jdk-8u361-linux-aarch64.rpm jdk-8u361-linux-i586.rpm jdk-8...
jdk1.8 jdk-8u5-windows-i586 32位官方正式版 jdk1.8 jdk-8u5-windows-i586 32位官方正式版
中文版的JDK,能让你更加清楚的知道如何运用API,能更加方便你的查询。
jdk6.0-04.zipjdk6.0-04.zipjdk6.0-04.zipjdk6.0-04.zip
深入浅出JDK6.0光盘内容 从Java语言的特点、语法、开发环境入手
这个是安装开发工具java jdk 有很多用途
最新版本的jdk欢迎大家来下载!最新版本的jdk欢迎大家来下载!