• web服务器


    为什么要有web服务器?

      比如我在本机写一个text.html文件,外界是不能直接访问的。如果外界访问的话,必须通过一个网络程序。当IE访问到这个网络程序的时候,就可以访问到text.html的内容

      理论上来讲,一个web程序应该对应一个网络程序。现在已经有了一个统一的网络程序,就是web服务器

         这样的话,当我们把web程序写好了之后,直接往web服务器里一扔就行了

    编写一个简单的网络程序

    编写一个MyServer.java文件

    import java.net.*;
    import java.io.*;
    
    public class MyServer
    {
       public static void main(String args[]) throws Exception
       {
            ServerSocket server = new ServerSocket(9999);  //监听9999端口
            Socket sock = server.accept();                 //建立一个客户机的Socket,通过这个Socket与客户机进行数据读写
    
    
            FileInputStream in = new FileInputStream ("D:\text.html");//读到数据,读到web资源
            OutputStream out =  sock.getOutputStream();       //通过sock写出去
    
            int len=0;
            byte buffer[] = new byte[1024];
            while((len=in.read(buffer))>0)
             {
                   out.write(buffer,0,len);
              }
    
           in.close();
           out.close();
           sock.close();
           server.close();
       }
    }

      serversocket 建立的是socket的服务端, socket建立的是客户端。.

    然后编译并执行这个文件

    在浏览器中输入 http://localhost:9999/   即可访问到text.html中的内容

    tomcat服务器

    是Apache公司开发的tomcat服务器,该服务器支持全部的jsp以及Servlet规范(j2ee有十三门技术,tomcat只支持这两种技术写的程序)

  • 相关阅读:
    Serveral effective linux commands
    Amber learning note A8: Loop Dynamics of the HIV-1 Integrase Core Domain
    amber初学……
    anaconda使用
    python中的一些语法
    python中的OOP
    python中的模块
    将python程序打包成exe
    python-执行过程
    python基础
  • 原文地址:https://www.cnblogs.com/tech-bird/p/3804323.html
Copyright © 2020-2023  润新知