Fork me on GitHub

服务器的小程序,可以通过浏览器访问该服务器自定义的内容

 1 import java.io.IOException;
 2 import java.io.PrintWriter;
 3 import java.net.ServerSocket;
 4 import java.net.Socket;
 5 
 6 //可以通过你的浏览器的客户端来访问
 7 //对于Tomcat理解方式:就是一种用纯java语言编写的面向服务器的软件。
 8 public class ServerDome {
 9     public static void main(String[] args) throws IOException {
10         while(true){
11             //建立服务器对象,并指定监听的端口号
12         ServerSocket ss=new ServerSocket(8080);
13         
14         //等待客户端发送通信
15         Socket s=ss.accept();
16         System.out.println(s.getInetAddress().getHostAddress());//留下你的ip
17         PrintWriter out=new PrintWriter(s.getOutputStream(),true);//就是在你的客户端上打印
18         
19         //行内样式
20         out.println("<div style='padding:5px 10px 20px 30px;background-color:red;width:300px;height:300px;float;left>" +
21                 "baoshengbo" +
22                 "</div> ");
23 
24         out.println("<div style='padding:5px 10px 20px 30px;background-color:green;width:300px;height:300px;float;left>" +
25                 "baoshengbo" +
26                 "</div>");
27         
28         
29         out.println("<font color='red' size='7'>开始做网页了</font>");
30         out.println("<a href='http://www.baidu.com/'>click</a>");
31         s.close();//关闭
32         ss.close();
33         }
34     }
35 }

 

posted @ 2017-02-12 15:50  ChangeSub  阅读(856)  评论(0编辑  收藏  举报