黑马程序员技术交流社区
标题:
帮忙看下为啥这个网页显示不出来
[打印本页]
作者:
费破的可
时间:
2013-11-12 13:38
标题:
帮忙看下为啥这个网页显示不出来
import java.io.*;
import java.awt.event.*;
import java.awt.*;
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);//文本区具有指定的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);
}
public void myEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
okBut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
d.setVisible(false);//实现退出
}
});
d.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
d.setVisible(false);
}
});
but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
showDir();
}
catch (Exception ee)
{
}
}
});
tf.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
try
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
showDir();
}
catch (Exception ee)
{
}
}
});
}
private void showDir()throws Exception
{
ta.setText("");//清空数据
String url = tf.getText();//http://192.168.1.106:8080/examples/deno.html
int index1 = url.indexOf("//")+2;
int index2 = url.indexOf("/",index1);
String str = url.substring(index1,index2);
String[] arr = str.split(":");
String host = arr[0];
int port = Integer.parseInt(arr[1]);
String path = url.substring(index2);
//ta.setText(str+";;;;;"+path);
Socket s = new Socket(host,port);
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
out.println("GET "+path+ " HTTP/1.1");
out.println("Accept: */*");
out.println("Accept-Language: zh-CN");
out.println("Host: 192.168.1.106:8080");
out.println("Connection: closed");
out.println();
out.println();
BufferedReader bufr = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = null;
while ((line=bufr.readLine())!=null)
{
//System.out.println(line);
ta.append(line+"\r\n");
}
s.close();
}
public static void main(String[] args)
{
new MyIEByGUI();
}
}
界面输入http://192.168.1.106:8080/examples/deno.html、
打印结果是这个HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Tue, 12 Nov 2013 05:32:10 GMT
Connection: close
0
而不是网页内容求大神来解决下
作者:
FFF
时间:
2013-11-14 21:03
如果问题已经解决,请及时修改主题为“提问结束”。
修改主题的方法链接
http://bbs.itheima.com/thread-89313-1-1.html
如果没有解决,可能你的问题问得不够清楚。可以重新发问的哦~
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2