应该不是太难吧。下面是一个例子:将一个页面读入到EditorPane中。 JEditorPane jep = new JEditorPane();
jep.setEditable(false);
EditorKit htmlKit = jep.getEditorKitForContentType("text/html");
HTMLDocument doc = (HTMLDocument) htmlKit.createDefaultDocument();
jep.setEditorKit(htmlKit);
try {
URL u = new URL("http://www.macfaq.com");
InputStream in = u.openStream();
jep.read(in, doc);
}
catch (IOException e) {
System.err.println(e);
}
JScrollPane scrollPane = new JScrollPane(jep);
JFrame f = new JFrame("Macfaq");
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.getContentPane().add(scrollPane);
f.setSize(512, 342);
f.show();如果JSP页面需要参数,可以这样写“http://www.macfaq.com?param1=test¶m2=test”
jep.setEditable(false);
EditorKit htmlKit = jep.getEditorKitForContentType("text/html");
HTMLDocument doc = (HTMLDocument) htmlKit.createDefaultDocument();
jep.setEditorKit(htmlKit);
try {
URL u = new URL("http://www.macfaq.com");
InputStream in = u.openStream();
jep.read(in, doc);
}
catch (IOException e) {
System.err.println(e);
}
JScrollPane scrollPane = new JScrollPane(jep);
JFrame f = new JFrame("Macfaq");
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.getContentPane().add(scrollPane);
f.setSize(512, 342);
f.show();如果JSP页面需要参数,可以这样写“http://www.macfaq.com?param1=test¶m2=test”
<%String filename=(String)request.getParameter("fileName");
//System.out.println("Line 4 In MeetingFileDown.jsp filename="+filename);
//设置响应头和下载保存的文件名
int index=filename.lastIndexOf("/");
String downfile=filename.substring(index+1);response.setContentType("APPLICATION/OCTET-STREAM");
//response.setHeader("Content-Type","attachment");
response.setHeader("Content-disposition","attachment;filename="+downfile);
//打开指定文件的流信息
File f=new File(filename);
java.io.FileInputStream fileIn=new java.io.FileInputStream(f);
//写出流信息
int i;
ServletOutputStream sos=response.getOutputStream();
int i_length=fileIn.available();
byte buf_1[]=new byte[i_length];
while(i_length>0){
fileIn.read(buf_1);
sos.write(buf_1);
i_length=fileIn.available();
}
sos.flush();
sos.close();
fileIn.close();%>======
在这个jsp页面中,本来显示在网页上的内容都将下载。你自己稍微修改一下应该就可以用的。
不是要自己作浏览器,这个需求是应用的一部分而已。
to moonyuezhao(月昭)
你的这个是将jsp页面提供下载了,我不是要这样的结果。需要的是jsp页面执行完了之后,生成的html,重定向在服务器端。(有很多jsp页面,写入zip包中)。