用javaweb怎么写

1.如何用java写一个webserver你从VeryCD上下一个 MyEclipse8GA 软件 (Java 开发IDE工具),欢迎页面就有web service 的Demo,在其Help里有步骤,及代码 。如果你的课程设计没有那么严格内容的话,完全没有问题 。
很Easy,5分钟就能把 服务端和库户端建立起来 。
如果还不明白的话,把你发纸条给我留言,我把 服务端和客户端 Demo代码给你,但是你还是需要下载 MyEclipse 8 GA 工具,否则你看起来会很难受 ^0^
Over!
2.我想用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.(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();。