當前位置:首頁 » 網頁前端 » javawebserver伺服器
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

javawebserver伺服器

發布時間: 2022-12-13 03:11:39

① 北大青鳥java培訓:web伺服器類型介紹

web應用的運營都是基於web伺服器的存在才能實現的。
今天我們就一起來了解一下,目前比較常見的一些web伺服器都有哪些類型。
1、Tomcat伺服器目前非常流行的Tomcat伺服器是Apache-Jarkarta開源項目中的一個子項目,是一個小型、輕量級的支持JSP和Servlet技術的Web伺服器,也是初學者學習開發JSP應用的選。
2、Resin伺服器Resin是Caucho公司的產品,是一個非常流行的支持Servlet和JSP的伺服器,速度非常快。
Resin本身包含了一個支持HTML的Web伺服器,這使它不僅可以顯示動態內容,而且顯示靜態內容的能力也毫不遜色,因此許多網站都是使用Resin伺服器構建3、JBoss伺服器JBoss是一個種遵從JavaEE規范的、開放源代碼的、純Java的EJB伺服器,對於J2EE有很好的支持。
JBoss採用JMLAPI實現軟體模塊的集成與管理,其核心服務又是提供EJB伺服器,不包含Servlet和JSP的Web容器,不過它可以和Tomcat完美結合4、WebSphere伺服器WebSphere是IBM公司的產品,可進一步細分為WebSpherePerformancePack、CacheManager和WebSphereApplicationServer等系列,其中WebSphereApplicationServer是基於Java的應用環境,可以運行於SunSolaris、WindowsNT等多種操作系統平台,用於建立、部署和管理Internet和IntranetWeb應用程序。
5、WebLogic伺服器WebLogic是BEA公司的產品(現在已經被Oracle收購),可進一步細分為WebLogicServer、WebLogicEnterprise和WebLogicPortal等系列,其中WebLogicServer的功能特別強大。
WebLogic支持企業級的、多層次的和完全分布式的Web應用,並且伺服器的配置簡單、界面友好。
IT培訓http://www.kmbdqn.cn/認為對於那些正在尋求能夠提供Java平台所擁有的一切應用伺服器的用戶來說,WebLogic是一個十分理想的選擇。

② 了解Web伺服器的種類有哪些嗎各自有哪些優缺點

現在的Web伺服器種類繁多,大家在做項目的時候可以根據自己的需求靈活選擇。下面和大家分享一下有哪些Web伺服器,以及它們的優缺點。

操作方法

01街頭流氓

Apache又稱httpd server,是目前應用最廣泛的web伺服器,應用於各種平台。當Apache首次推出時,它有許多缺陷。現在已經修復完善了。如果你是一名web伺服器研究人員,邊肖建議你必須學會使用Apache。

優點:緊湊、靈活、可擴展、穩定。

缺點:軟體是開源的,所以很多漏洞可能很容易被發現。

08碼頭

Jetty是一個專用於Java Web的伺服器。它用於運行Servlet程序,是眾多伺服器中最受限制的。邊肖不建議你掌握這個伺服器。

優點:內容簡單,容易掌握。

③ java實現調用webserver

一、利用jdk web服務api實現,這里使用基於 SOAP message 的 Web 服務
1.首先建立一個Web services EndPoint:

Java代碼

package Hello;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;

@WebService
public class Hello {

@WebMethod
public String hello(String name) {
return "Hello, " + name + "\n";
}

public static void main(String[] args) {
// create and publish an endpoint
Hello hello = new Hello();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/hello", hello);
}
}

Java代碼

package Hello;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;

@WebService
public class Hello {

@WebMethod
public String hello(String name) {
return "Hello, " + name + "\n";
}

public static void main(String[] args) {
// create and publish an endpoint
Hello hello = new Hello();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/hello", hello);
}
}

2.使用 apt 編譯 Hello.java(例:apt -d [存放編譯後的文件目錄] Hello.java ) ,會生成 jaws目錄
3.使用java Hello.Hello運行,然後將瀏覽器指向http://localhost:8080/hello?wsdl就會出現下列顯示
4.使用wsimport 生成客戶端
使用如下:wsimport -p . -keep http://localhost:8080/hello?wsdl
5.客戶端程序:

Java代碼

class HelloClient{
public static void main(String args[]) {
HelloService service = new HelloService();
Hello helloProxy = service.getHelloPort();
String hello = helloProxy.hello("你好");
System.out.println(hello);
}
}

Java代碼

class HelloClient{
public static void main(String args[]) {
HelloService service = new HelloService();
Hello helloProxy = service.getHelloPort();
String hello = helloProxy.hello("你好");
System.out.println(hello);
}
}

④ web伺服器有哪些

常見的WEB伺服器有:

1、ApacheApache是世界使用排名第一的Web伺服器軟體。

它可以運行在幾乎所有廣泛使用的計算機平台上。Apache源於NCSAhttpd伺服器,經過多次修改,成為世界上最流行的Web伺服器軟體之一。Apache的特點是簡單、速度快、性能穩定,並可做代理伺服器來使用。

2、IIS是英文Internet Information Server的縮寫,譯成中文就是"Internet信息服務"的意思。

它是微軟公司主推的伺服器,最新的版本是Windows2008裡麵包含的IIS 7,IIS與Window Server完全集成在一起,因而用戶能夠利用Windows Server和NTFS(NT File System,NT的文件系統)內置的安全特性,建立強大,靈活而安全的Internet和Intranet站點。

3、GFEGoogle的web伺服器,用戶數量激增。目前緊逼iis。

4、Nginx不僅是一個小巧且高效的HTTP伺服器,也可以做一個高效的負載均衡反向代理,通過它接受用戶的請求並分發到多個Mongrel進程可以極大提高Rails應用的並發能力。

5、Lighttpd

是由德國人 Jan Kneschke 領導開發的,基於BSD許可的開源WEB伺服器軟體,其根本的目的是提供一個專門針對高性能網站,安全、快速、兼容性好並且靈活的web server環境。具有非常低的內存開銷,CPU佔用率低,效能好,以及豐富的模塊等特點。

Lighttpd 是眾多OpenSource輕量級的web server中較為優秀的一個。支持FastCGI, CGI, Auth, 輸出壓縮(output compress), URL重寫, Alias等重要功能。

6、Zeus是一個運行於Unix下的非常優秀的Web Server,據說性能超過Apache,是效率最高的Web Server之一。

7、Sun的Java系統Web伺服器也就是以前的Sun ONE Web Server。主要出現在那些運行Sun的Solaris操作系統的關鍵任務級Web伺服器上。

它最新的版本號是6.1,可以支持x86版本Solaris,Red Hat Linux,HP-UX 11i, IBM AIX,甚至可以支持Windows,但它的大多數用戶都選擇了SPARC版本的Solaris操作系統。

8、Resin提供了最快的jsp/servlets運行平台。在java和javascript的支持下,Resin可以為任務靈活選用合適的開發語言。Resin的一種先進的語言XSL(XML stylesheet language)可以使得形式和內容相分離。

(4)javawebserver伺服器擴展閱讀:

1、Apache伺服器優缺點:

優點:小巧,靈活,可擴展,穩定;

缺點:軟體開源,所以很多的漏洞可能很容易被人查找到。

2、Nginx伺服器優缺點:

優點:壓縮率高,支持負載均衡,速度快;

缺點:需要掌握熟練的Linux命令才能應用;

3、IIS伺服器優缺點:

優點:安裝配置簡單,學習起來容易;

缺點:平台適用性單一,安全性有待提高。

4、WebLogic伺服器優缺點:

優點:安全性高,專業性強,耦合度低;

缺點:不容易掌握,需要有一定的專業積累才能熟練應用。

⑤ java程序怎麼在Web伺服器里運行.

如何用Java實現Web伺服器 一、HTTP協議的作用原理

WWW是以Internet作為傳輸媒介的一個應用系統,WWW網上最基本的傳輸單位是Web網頁。WWW的工作基於客戶機/伺服器計算模型,由Web 瀏覽器(客戶機)和Web伺服器(伺服器)構成,兩者之間採用超文本傳送協議(HTTP)進行通信。HTTP協議是基於TCP/IP協議之上的協議,是Web瀏覽器和Web伺服器之間的應用層協議,是通用的、無狀態的、面向對象的協議。HTTP協議的作用原理包括四個步驟:

(1) 連接:Web瀏覽器與Web伺服器建立連接,打開一個稱為socket(套接字)的虛擬文件,此文件的建立標志著連接建立成功。

(2) 請求:Web瀏覽器通過socket向Web伺服器提交請求。HTTP的請求一般是GET或POST命令(POST用於FORM參數的傳遞)。GET命令的格式為:

GET 路徑/文件名 HTTP/1.0

文件名指出所訪問的文件,HTTP/1.0指出Web瀏覽器使用的HTTP版本。

(3) 應答:Web瀏覽器提交請求後,通過HTTP協議傳送給Web伺服器。Web伺服器接到後,進行事務處理,處理結果又通過HTTP傳回給Web瀏覽器,從而在Web瀏覽器上顯示出所請求的頁面。

例:假設客戶機與www.mycompany.com:8080/mydir/index.html建立了連接,就會發送GET命令:GET /mydir/index.html HTTP/1.0.主機名為www.mycompany.com的Web伺服器從它的文檔空間中搜索子目錄mydir的文件index.html.如果找到該文件,Web伺服器把該文件內容傳送給相應的Web瀏覽器。

為了告知 Web瀏覽器傳送內容的類型,Web伺服器首先傳送一些HTTP頭信息,然後傳送具體內容(即HTTP體信息),HTTP頭信息和HTTP體信息之間用一個空行分開。

常用的HTTP頭信息有:

① HTTP 1.0 200 OK

這是Web伺服器應答的第一行,列出伺服器正在運行的HTTP版本號和應答代碼。代碼「200 OK」表示請求完成。

② MIME_Version:1.0

它指示MIME類型的版本。

③ content_type:類型

這個頭信息非常重要,它指示HTTP體信息的MIME類型。如:content_type:text/html指示傳送的數據是HTML文檔。

④ content_length:長度值

它指示HTTP體信息的長度(位元組)。

(4) 關閉連接:當應答結束後,Web瀏覽器與Web伺服器必須斷開,以保證其它Web瀏覽器能夠與Web伺服器建立連接。

二、Java實現Web伺服器功能的程序設計

根據上述HTTP協議的作用原理,實現GET請求的Web伺服器程序的方法如下:

(1) 創建ServerSocket類對象,監聽埠8080.這是為了區別於HTTP的標准TCP/IP埠80而取的;

(2) 等待、接受客戶機連接到埠8080,得到與客戶機連接的socket;

(3) 創建與socket字相關聯的輸入流instream和輸出流outstream;

(4) 從與socket關聯的輸入流instream中讀取一行客戶機提交的請求信息,請求信息的格式為:GET 路徑/文件名 HTTP/1.0

(5) 從請求信息中獲取請求類型。如果請求類型是GET,則從請求信息中獲取所訪問的HTML文件名。沒有HTML文件名時,則以index.html作為文件名;

(6) 如果HTML文件存在,則打開HTML文件,把HTTP頭信息和HTML文件內容通過socket傳回給Web瀏覽器,然後關閉文件。否則發送錯誤信息給Web瀏覽器;

(7) 關閉與相應Web瀏覽器連接的socket字。

下面的程序是根據上述方法編寫的、可實現多線程的Web伺服器,以保證多個客戶機能同時與該Web伺服器連接。

程序1:WebServer.java文件

//WebServer.java 用JAVA編寫Web伺服器

import java.io.*;

import java.net.*;

public class WebServer {

public static void main(String args[]) {

int i=1, PORT=8080;

ServerSocket server=null;

Socket client=null;

try {

server=new ServerSocket(PORT);

System.out.println("Web Server is listening on port "+server.getLocalPort());

for (;;) {client=server.accept(); //接受客戶機的連接請求

new ConnectionThread(client,i)。start();

i++;

}

} catch (Exception e) {System.out.println(e);}

}

}

/* ConnnectionThread類完成與一個Web瀏覽器的通信 */

class ConnectionThread extends Thread {

Socket client; //連接Web瀏覽器的socket字

int counter; //計數器

public ConnectionThread(Socket cl,int c) {

client=cl;

counter=c;

}

public void run() //線程體

{try {

String destIP=client.getInetAddress()。toString(); //客戶機IP地址

int destport=client.getPort(); //客戶機埠號

System.out.println("Connection "+counter+":connected to "+destIP+" on port "+destport+".");

PrintStream outstream=new PrintStream(client.getOutputStream());

DataInputStream instream=new DataInputStream(client.getInputStream());

String inline=instream.readLine(); //讀取Web瀏覽器提交的請求信息

System.out.println("Received:"+inline);

if (getrequest(inline)) { //如果是GET請求

String filename=getfilename(inline);

File file=new File(filename);

if (file.exists()) { //若文件存在,則將文件送給Web瀏覽器

System.out.println(filename+" requested.");

outstream.println("HTTP/1.0 200 OK");

outstream.println("MIME_version:1.0");

outstream.println("Content_Type:text/html");

int len=(int)file.length();

outstream.println("Content_Length:"+len);

outstream.println("");

sendfile(outstream,file); //發送文件

outstream.flush();

} else { //文件不存在時

String notfound="

Error 404-file not found
";

outstream.println("HTTP/1.0 404 no found");

outstream.println("Content_Type:text/html");

outstream.println("Content_Length:"+notfound.length()+2);

outstream.println("");

outstream.println(notfound);

outstream.flush();

}

http://java.chinaitlab.com/advance/519981.html

⑥ Java:除了tomcat以外,還有哪些常用的Web伺服器呢

1、weblogic

WebLogic是美國bea公司出品的一個application server確切的說是一個基於j2ee架構的中間件。BEA WebLogic是用於開發、集成、部署和管理大型分布式Web應用、網路應用和資料庫應用的Java應用伺服器。將Java的動態功能和Java Enterprise標準的安全性引入大型網路應用的開發、集成、部署和管理之中。

2、webSphere

WebSphere是 IBM 的集成軟體平台。它包含了編寫、運行和監視全天候的工業強度的隨需應變 Web 應用程序和跨平台、跨產品解決方案所需要的整個中間件基礎設施。

如伺服器、服務和工具。WebSphere 提供了可靠、靈活和健壯的集成軟體。

3、JBoss

JBoss是一個管理EJB的容器和伺服器,支持EJB 1.1、EJB 2.0和EJB3.0的規范。但JBoss核心服務不包括支持servlet/JSP的WEB容器,一般與Tomcat或Jetty綁定使用。2006年,Jboss公司被Redhat公司收購。

4、 Apache

Apache源於NCSAhttpd伺服器,經過多次修改,成為世界上最流行的Web伺服器軟體之一。

Apache是自由軟體,所以不斷有人來為它開發新的功能、新的特性、修改原來的缺陷。Apache的特點是簡單、速度快、性能穩定,並可做代理伺服器來使用。

本來它只用於小型或試驗Internet網路,後來逐步擴充到各種Unix系統中,尤其對Linux的支持相當完美。

Apache是以進程為基礎的結構,進程要比線程消耗更多的系統開支,不太適合於多處理器環境,因此,在一個Apache Web站點擴容時,通常是增加伺服器或擴充群集節點而不是增加處理器。

到目前為止Apache仍然是世界上用的最多的Web伺服器,世界上很多著名的網站都是Apache的產物,它的成功之處主要在於它的源代碼開放、有一支開放的開發隊伍、支持跨平台的應用(可以運行在幾乎所有的Unix、Windows、Linux系統平台上)以及它的可移植性等方面。

5、 IIS

Microsoft的Web伺服器產品為InternetInformation Server (IIS), IIS 是允許在公共Intranet或Internet上發布信息的Web伺服器。

IIS是目前最流行的Web伺服器產品之一,很多著名的網站都是建立在IIS的平台上。IIS提供了一個圖形界面的管理工具,稱為 Internet服務管理器,可用於監視配置和控制Internet服務。

IIS是一種Web服務組件,其中包括Web伺服器、FTP伺服器、NNTP伺服器和SMTP伺服器,分別用於網頁瀏覽、文件傳輸、新聞服務和郵件發送等方面,它使得在網路(包括互聯網和區域網)上發布信息成了一件很容易的事。

它提供ISAPI(IntranetServer API)作為擴展Web伺服器功能的編程介面;同時它還提供一個Internet資料庫連接器,可以實現對資料庫的查詢和更新。

⑦ java構建最簡單的 Web Server

安裝一個tomcat就完事了…………
weblogic;websphere
類似
調用Hello JAVA頁面,嘿嘿
網上到處都是,偏你們老師跳神把要求寫得這么古里古怪,太學術了。

⑧ 我想用java寫一個簡單的web server,應該怎麼寫呀

我原來寫過一個很簡單的,可以指定你存放網頁的文件夾,可以指定允許訪問的IP,給你源碼看看吧。public class WebServer {
static Button btReloadIP=new Button("更新合法IP列表");
static Button btAllow=new Button("允許此IP");
static Button btRepel=new Button("拒絕此IP");
static JTextField tfNewIP=new JTextField(20);
static JPanel pane=new JPanel();
static JTextField tfState=new JTextField(25);
static TextField tfURL=new TextField("G:\\webServer2\\",28);
static TextField tfPort=new TextField("10288",3);
static Button btStart=new Button("啟動伺服器");
static Button btStop=new Button("停止伺服器");
private static int IPnum=0;
public static boolean IPadmin=false;
static boolean click=false;
private static String url;
private static String[] checkIP=new String[255];
private static Thread serverThread=null;
private static Socket connectionSocket=null;
private static ServerSocket listenSocket=null;
public WebServer() throws IOException{
serverThread=new Thread(new Runnable(){
public void run(){
try {
listenSocket = new ServerSocket(Integer.parseInt(tfPort.getText()));
} catch (IOException e) { }
while(true){
try {
connectionSocket=listenSocket.accept();
@SuppressWarnings("unused")
webClient client=new webClient(connectionSocket);
} catch (IOException e) {
}
}
}
});
}
public static void main(String args[])throws Exception{
GUI();
}
public static void GUI(){
JFrame f=new JFrame("小白兔Web伺服器(BY 丁尋)");
f.setSize(300,200);
f.setLocation(500, 300);
f.getContentPane().add(pane,BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
//不可以變大變小
f.setResizable(false);
pane.add(new JLabel("埠號:"));
pane.add(tfPort);
pane.add(btStart);
pane.add(btStop);
pane.add(new JLabel("配置路徑"));
pane.add(tfURL);
pane.add(tfState);
pane.add(new JLabel("新IP請求"));
pane.add(tfNewIP);
pane.add(btAllow);
pane.add(btRepel);
pane.add(btReloadIP); btStart.addActionListener(new Listener());
btStop.addActionListener(new Listener());
btAllow.addActionListener(new Listener());
btRepel.addActionListener(new Listener());
btReloadIP.addActionListener(new Listener());

}
static class Listener implements ActionListener {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent event) {
if(event.getActionCommand()=="啟動伺服器"){
try {
url=tfURL.getText();
readIP();
tfState.setText("伺服器已經啟動......地址:"
+InetAddress.getLocalHost().toString());
} catch (Exception e) {
e.printStackTrace();
} try {
new WebServer();
} catch (IOException e) {
e.printStackTrace();
} serverThread.start(); btStart.setEnabled(false);
tfPort.setEditable(false);
btStop.setEnabled(true);
tfURL.setEditable(false);
btReloadIP.setEnabled(true);
}
if(event.getActionCommand()=="停止伺服器"){
serverThread.stop();
tfState.setText("伺服器已經停止");
btStart.setEnabled(true);
tfPort.setEditable(true);
btStop.setEnabled(false);
tfURL.setEditable(true);
btReloadIP.setEnabled(false);
}
if(event.getActionCommand()=="允許此IP"){
IPadmin=true;
//serverThread.start();
click=true;
btAllow.setEnabled(false);
btRepel.setEnabled(false);
tfNewIP.setText(null);
}
if(event.getActionCommand()=="拒絕此IP"){
click=true;
IPadmin=false;
//serverThread.start();
btAllow.setEnabled(false);
btRepel.setEnabled(false);
tfNewIP.setText(null);
}
if(event.getActionCommand()=="更新合法IP列表"){
try {
readIP();
} catch (IOException e) {
// e.printStackTrace();
}
}
}
}

public static void readIP() throws IOException{
int i=0;
byte[] ips = new byte[65535];
File IPfile=new File(url+"checkIP.txt");
FileInputStream fileReader=new FileInputStream(IPfile);
fileReader.read(ips);
fileReader.close();
String strip=new String(ips);
StringTokenizer getIP=new StringTokenizer(strip,System.getProperty("line.separator"));

for(;;){
if(getIP.hasMoreTokens()){
checkIP[i]=getIP.nextToken();
System.out.println(checkIP[i]);
i++;
}
else{break;}
}
IPnum=i;

}
public static void disconnect(webClient c){

try {
//c.stop();
c.socket.close();
c.socket=null;
c=null; } catch (IOException e) {
e.printStackTrace();
}
//
}
class webClient extends Thread{
boolean check=true;
boolean send=false;
Socket socket;
BufferedReader inFromClient=null;
DataOutputStream outToClient=null;
String fileName;
String requestMessageLine;
StringTokenizer tokenizedLine=null;
FileInputStream inFile=null;
byte[] fileInBytes=null;
int numOfBytes=0;
File afile=new File(url+"log.html");
byte[] b;
public webClient(Socket s) throws IOException{
FileOutputStream out=new FileOutputStream(afile,true);
StringBuffer str=new StringBuffer();
SimpleDateFormat formatter=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String time=formatter.format(new Date());
socket=s;
str.append(time+" Client_IP:"+socket.getInetAddress().toString()+
" Client_Port:"+socket.getPort()+"<br>"+
System.getProperty("line.separator")
);
b=(new String(str)).getBytes();
System.err.println(new String(str));
out.write(b);
out.close();
inFromClient=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
outToClient=new DataOutputStream(socket.getOutputStream());
if(!checkIP(socket)){
String strWait="<html>" +
"<title>等待驗證</title>" +
"<body>正在等待管理員驗證您的IP是否合法,請稍候......<br><br>" +
"(如果頁面沒有自動跳轉,請每5秒鍾刷新一次," +
"以判斷管理員是否已經允許您進入)</body>" +
"</html>";
byte[] waiting=strWait.getBytes();
outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n");
outToClient.writeBytes("Content-Type: text/html\r\n");
outToClient.writeBytes("Content-Length: "+waiting.length+"\r\n");
outToClient.writeBytes("\r\n");
outToClient.write(waiting,0,waiting.length);
if(!admin()){
return;
}
WebServer.IPadmin=false;
}
this.start(); }
public void receive() throws IOException{
while(socket!=null){
requestMessageLine=inFromClient.readLine();
if(requestMessageLine.length()==0){break;}
System.out.println(requestMessageLine);
tokenizedLine=new StringTokenizer(requestMessageLine);
if(tokenizedLine.hasMoreTokens()){
String strhead=tokenizedLine.nextToken();
if(strhead.equals("GET")){
send=true;
fileName=tokenizedLine.nextToken();
if(fileName.equals("/")){
fileName="index.html";
}
else if(fileName.startsWith("/")){
fileName=fileName.substring(1);
fileName=fileName.replace("%5C", "/");
fileName=fileName.replace("%20", " ");
//如果是文件 ,不要check
check=false;
}
}//endnexttoken
if(check){
if(strhead.equals("User-Agent:")){
if(requestMessageLine.contains("Firefox/3")){
System.err.println("true");
}
else{
System.err.println("false");
fileName="ERROR.html";
send=true;
}
}
}
//....
}//endhastoken
}//endwhile
if(send){
readFile();
send(fileInBytes, numOfBytes);
} }
public void send(byte[] fileInBytes,int numOfBytes) throws IOException{
outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n"); if(fileName.endsWith(".jpg")){
outToClient.writeBytes("Content-Type: image/jpg\r\n");
}
else if(fileName.endsWith(".gif")){
outToClient.writeBytes("Content-Type: image/gif\r\n");
}
else if(fileName.endsWith(".wmv")){
outToClient.writeBytes("Content-Type: video/x-ms-wmv\r\n");
}
else if(fileName.endsWith(".avi")){
outToClient.writeBytes("Content-Type: video/avi\r\n");
}
else if(fileName.endsWith(".html")||fileName.endsWith(".htm")){
outToClient.writeBytes("Content-Type: text/html\r\n");
}
outToClient.writeBytes("Content-Length: "+numOfBytes+"\r\n"); outToClient.writeBytes("\r\n");
outToClient.write(fileInBytes,0,numOfBytes);
}
//得到文件
public void readFile() throws IOException{
File file=new File(url+fileName);
b=(" Client_Request:"+fileName+"<br>"+
System.getProperty("line.separator")).getBytes();
FileOutputStream out=new FileOutputStream(afile,true);
out.write(b);
out.close();
numOfBytes=(int)file.length();
inFile=new FileInputStream(url+fileName);
fileInBytes=new byte[numOfBytes];
inFile.read(fileInBytes);
inFile.close(); }
public boolean checkIP(Socket skt){
for(int i=0;i<WebServer.IPnum;i++){
if(skt.getInetAddress().toString().equals(checkIP[i])){
return true;
}
}
return false;

}
public boolean admin() throws IOException{
WebServer.tfNewIP.setText("IP:"+socket.getInetAddress().toString()+
" PORT:"+socket.getPort());
WebServer.btAllow.setEnabled(true);
WebServer.btRepel.setEnabled(true);
while(!click){}
click=false;

if(WebServer.IPadmin){
File IPFile=new File(url+"checkIP.txt");
FileOutputStream appIP=new FileOutputStream(IPFile,true);
byte[] ips=(socket.getInetAddress().toString()+
System.getProperty("line.separator")).getBytes();
appIP.write(ips);
appIP.close();
//WebServer.readIP();
WebServer.checkIP[IPnum]=socket.getInetAddress().toString();
WebServer.IPnum++;
return true;
}
else{
WebServer.disconnect(this);
return false;
}
}

public void run(){
try {
receive();
} catch (IOException e) {
}
WebServer.disconnect(this);
}
}}