java模拟服务器交互_java 模拟浏览器与Tomcat服务器交互

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

class  MyIEByGUI

{

private Frame f;

private TextField tf;

private Button but;

private TextArea ta;

private Dialog d;

private Label lab;

private Button okBut;

MyIEByGUI()

{

init();

}

public void init()

{

f = new Frame("my window");

f.setBounds(300,100,600,500);

f.setLayout(new FlowLayout());

tf = new TextField(60);

but = new Button("转到");

ta = new TextArea(25,70);

d = new Dialog(f,"提示信息-self",true);

d.setBounds(400,200,240,150);

d.setLayout(new FlowLayout());

lab = new Label();

okBut = new Button("确定");

d.add(lab);

d.add(okBut);

f.add(tf);

f.add(but);

f.add(ta);

myEvent();

f.setVisible(true);

}

private void  myEvent()

{

okBut.addActionListener(new ActionListener()//对话框中的确定按钮

{

public void actionPerformed(ActionEvent

e)//点击对话框中的确定按钮,关闭对话框

{

d.setVisible(false);

}

});

d.addWindowListener(new WindowAdapter()//对话框

{

public void windowClosing(WindowEvent e)//添加对话框

{

d.setVisible(false);

}

});

tf.addKeyListener(new KeyAdapter()//文本框

{

public void keyPressed(KeyEvent e)

{

try

{

if(e.getKeyCode()==KeyEvent.VK_ENTER)//文本框中按下回车键,显示

showDir();

}

catch (Exception ex)

{

}

}

});

but.addActionListener(new ActionListener()//窗口中的转到按钮

{

public void actionPerformed(ActionEvent e)

{

try

{

showDir();//显示目录

}

catch (Exception ex)

{

}

}

});

f.addWindowListener(new WindowAdapter()//窗口

{

public void windowClosing(WindowEvent e)//点击关闭按钮

{

System.exit(0);

}

});

}

private void showDir()throws Exception

{

*");

out.println("Accept-Language: zh-cn");

out.println("Host: 192.168.1.254:11000");

out.println("Connection: closed");

out.println();

out.println();

BufferedReader bufr = new BufferedReader(new

InputStreamReader(s.getInputStream()));//读取 Tomcat返回的数据

String line = null;

while((line=bufr.readLine())!=null)

{

ta.append(line+"\r\n");//显示在文本区域中

}

s.close();

*/

//URL运用应用层的HTTP协议

ta.setText("");

String urlPath =

tf.getText();//http://192.168.1.254:8080/myweb/demo.html

URL url = new URL(urlPath);

URLConnection conn = url.openConnection();

InputStream in = conn.getInputStream();

}

public static void main(String[] args)

{

new MyIEByGUI();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值