import java.io.*;
import java.awt.*;
import java.util.*;
import java.net.*;
import java.awt.event.*;
import java.lang.*;
import java.sql.*;
import java.util.Date;
import java.sql.ResultSet.*;
class Self{//日期mydatetime类
String year;
String month;
String day;
String datetime;
Date date;
String week;
Self()
{
date=new Date();
year=this.getyear();
month=this.getmonth();
day=this.getday();
datetime=this.getdatetime();
week=this.getWeek();
}
String getyear()
{
String temp;
int index;
index=this.date.toString().lastIndexOf(" ");
temp=this.date.toString().substring(index,date.toString().length());
return temp;
}
String getmonth()
{
String temp;
temp=this.date.toString().substring(4,7);
if(temp.equals("Feb"))
return "2";
else if(temp.equals("Mar"))
return "3";
else if(temp.equals("Apr"))
return "4";
else if(temp.equals("May"))
return "5";
else if(temp.equals("Jun"))
return "6";
else if(temp.equals("Jul"))
return "7";
else if(temp.equals("Aug"))
return "8";
else if(temp.equals("Sep"))
return "9";
else if(temp.equals("Oct"))
return "10";
else if(temp.equals("Nov"))
return "11";
else if(temp.equals("Dec"))
return "12";
else
return "1";
}
String getday()
{
String temp;
temp=date.toString().substring(8,10);
return temp;
}
String getdatetime()
{
String temp;
temp=date.toString().substring(11,19);
return temp;
}
String getWeek()
{
String temp=this.date.toString().substring(0,3);
if(temp.equals("Mon"))
{
return "星期一";
}
else if(temp.equals("Tue"))
{
return "星期二";
}
else if(temp.equals("Wed"))
{
return "星期三";
}
else if(temp.equals("Thu"))
{
return "星期四";
}
else if(temp.equals("Fri"))
{
return "星期五";
}
else if(temp.equals("Sat"))
{
return "星期六";
}
else if(temp.equals("Sun"))
{
return "星期七";
}
else
return "";
}
String Show()
{
return this.getyear()+"-"+this.getmonth()+"-"+this.getday()+" "+this.getdatetime();
}
}
/*class File_Name_Directory extends Frame implements ActionListener {
FileDialog File_Dialog;//根文件设置
Button Confirm;
Button Cancle;
Button Set_File;
TextField Directory_Name_Text;
TextField File_Name_Text;
Label Directory_Label;
Label File_Label;
String Root_File;
String Root_Directoy;
File_Name_Directory()
{
this.setTitle("根目录设置");
File_Dialog=new FileDialog(this,"根目录设置",FileDialog.LOAD);
Confirm=new Button("确定");
Set_File=new Button("设置");
Cancle=new Button("取消");
Directory_Label=new Label("根目录");
File_Label=new Label("默认Index文件");
File_Name_Text=new TextField();
Directory_Name_Text=new TextField();
this.setLayout(new GridLayout());
this.add(Directory_Label);
this.add(Directory_Name_Text);
this.add(File_Label);
this.add(File_Name_Text);
this.add(Set_File);
this.add(Confirm);
this.add(Cancle);
this.setResizable(false);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent windowevent)
{
setVisible(false);
}
});
Confirm.addActionListener(this);
Set_File.addActionListener(this);
Cancle.addActionListener(this);
this.pack();
this.setVisible(true);
}
String CheckInformation(String temp)
{
return temp;
}
public void actionPerformed(ActionEvent ee)
{
if(ee.getSource()==Confirm)
{
if(this.Directory_Name_Text.getText().length()!=0)
{
if(this.File_Name_Text.getText().length()!=0)
{
this.Root_File=this.File_Name_Text.getText();
System.out.println("current "+this.Root_File+"File");
this.Root_Directoy=this.Directory_Name_Text.getText();
System.out.println(this.Root_Directoy+"Directory");
}
else
{}
//this.setVisible(false);
}
else
{}
this.setVisible(false);
}
else if(ee.getSource()==Set_File)
{
this.File_Dialog.setVisible(true);
this.Directory_Name_Text.setText(this.File_Dialog.getDirectory());
this.File_Name_Text.setText(this.File_Dialog.getFile());
}
else if(ee.getSource()==Cancle)
{
this.File_Name_Text.setText("");
this.Directory_Name_Text.setText("");
}
}
}*/
class Help extends Frame implements ActionListener{
Button b;
TextArea information;
Help()
{
String author;
author="Author :Liubing"+"/n"+"Address:Jinan Univirsity School of Information and Technoloy "+"/n"+"TEL:(0531)6304501";
author=author+"/nQQ:286526084";
author=author+"/nVersion Information:Version 1.0 HTTP Common Server";
author=author+"/nUser Object :Web-Lover,Personnel-WebLover,Programmer of Web";
author=author+"/n Welcome to use ";
this.setLayout(new BorderLayout());
information=new TextArea(author);
information.setFont(new Font("Courier",Font.BOLD,12));
b=new Button("Exit");
this.setTitle("HTTP Author");
this.setBackground(Color.BLUE);
this.setSize(100,100);
this.setResizable(false);
this.add(information,BorderLayout.CENTER);
this.add(b,BorderLayout.NORTH);
this.information.setEnabled(false);
this.pack();
this.setVisible(true);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent windowEvent)
{
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent ac)
{
if(ac.getSource()==b)
{
this.setVisible(false);
}
}
}
class Infor implements Runnable{
Socket cSocket;
File file;
//Search_Add_Records search;
//String Directory;
public Infor(Socket cSocket)
{
try{
this.cSocket=cSocket;
// search.Get_Record();
//Directory=this.search.RootDirectory.replaceAll("
//","/");
//System.out.println(Directory+"RootDirectory");
}catch(Exception ecod)
{}
}
public void run()
{
try{
String Ip="localhost";
String AInfor;
String ADate;
String DDate;
int Port;
String File_Name;
// File file;
PrintStream response=new PrintStream(this.cSocket.getOutputStream());
BufferedReader request=new BufferedReader(new InputStreamReader(this.cSocket.getInputStream()));
String receive=request.readLine();
AInfor=receive;
Ip=this.cSocket.getInetAddress().getHostAddress();
ADate=new Self().Show().toString();
Port=this.cSocket.getPort();
int sp1=receive.indexOf(" ");
int sp2=receive.indexOf(" ",sp1+1);
File_Name=receive.substring(sp1+2,sp2);
if(File_Name.equals("")||File_Name.endsWith("/"))
{
//if(!this.search.RootFile.equals(""))
// File_Name=this.search.RootFile;//"index.htm";
//else
File_Name="index.htm";
}
// if(this.Directory.equals(""))
// file=new File("F:/li/倪/"+File_Name);//(+File_Name);
//else
//file=new File(this.Directory,File_Name);
file=new File("WWWRoot/"+File_Name);
System.out.println("Get :"+receive.toString());
if(file.exists()==true)
{
InputStream fs=new FileInputStream(file);
int number=fs.available();
byte []buf=new byte[1024];
while((number=fs.read(buf))>0)
{
response.write(buf,0,number);
}
DDate=new Self().Show().toString();
System.out.println(Ip+":"+AInfor);
System.out.println(ADate+":"+DDate+":"+Port);
fs.close();
response.close();
request.close();
this.cSocket.close();
}
else
{
String c="<html><title>刘冰提示你:</title><body>你无法打开此网页<p>请你与管理员联系</body></html>";
response.println(c);
}
}catch(Exception my_e)
{
System.out.println(my_e.toString());
}
}
}
class Server {
HttpServer Http_Server;
ServerSocket Server_Socket;
TextArea sStatus;
int Port;
public Server(HttpServer Http_Server)
{
try{
this.Port=80;
Server_Socket=new ServerSocket(this.Port);
this.Http_Server=Http_Server;
this.sStatus=this.Http_Server.Information;
this.sStatus.append("Http Server is ruunning....");
this.sStatus.append("/nThr current time is :"+new Self().Show());
}catch(Exception exception)
{
this.sStatus.append("Server can't running....");
}
while(true)
{
try{
Socket cSocket=Server_Socket.accept();
Infor Infor_Porcess=new Infor(cSocket);
Thread Tr=new Thread(Infor_Porcess);
Tr.start();
}catch(Exception excep)
{
this.sStatus.append("/nServer is in error....");
}
}
}
}
相关推荐
JAVA 网络编程服务器端例程,一个测试socket通信的比较好的例程
Java网络编程之TCP协议下—上传文件到服务器程序,欢迎大家下载和知道
简单的java服务器,可以支持http访问,利用serversocket实现
简易模拟tomcat服务器项目源码java学习CS架构网络编程;简易模拟tomcat服务器项目源码java学习CS架构网络编程;简易模拟tomcat服务器项目源码java学习CS架构网络编程;简易模拟tomcat服务器项目源码java学习CS架构...
无论你是经验丰富的网络开发人员、Java程序员新手,还是只希望对Java网络编程稍有些了解的人,都会发现《Java编程(第三版)》将成为你的书库中一个重要的部分。一旦开始使用Java网络API,只要你能想到它就能够做...
你将学习如何使用Java的网络类库既快速又轻松地完成常见的网络编程任务,如编写多线程服务器、加密通信、广播到本地网络,以及向服务器端程序提交数据。 作者哈诺德提供了真正可实用的程序来讲解他介绍的方法和类。...
基于HTTP协议的web服务器,NetBean下开发
java网络编程——网络版题库程序(主要技术java+socket+多线程+mysql),程序是C/S 版本的,由于服务器端是java写的,所有客户端使用android也是很容易与服务器对接的
java网络编程示例 实现客户机和服务器功能,客户机向服务器发送一条信息,服务器将所有信息转发给所有客户机
java网络编程:控制台输入,服务端代码!
网络编程,用Java实现服务器与客户端之间的交互教学
这是一本关于java网络编程实例的丛书,他可以帮助你增强java网路方面的知识和能力。
《Java网络编程》(第3版)有很多示例,包含了几千行可以实际工作的代码(所有代码都可以在线获得),实现了功能完整的网络客户端和服务器。无论是希望编写特殊用途的Web服务器、安全的在线订单接收程序、简单的组播...
Java服务器高级编程 Java服务器高级编程
Java网络编程之服务器套接字.pdf
java网络编程之简单客户端服务器定义.pdf
java网络编程之简单客户端服务器参照.pdf
Java网络编程的小例子,分服务器端和客户端,可以相互通信,有注释!
适合java初学者,可以帮助你们了解简单的图形化界面,和网络编程