请问大家一个问题,我在JSP页面用ServletOutputStream已经输出了一个图片了,请问,我还想输出JAVASRCIPT,代码怎么写?<%
FileInputStream in = new FileInputStream("d://house_1.jpg");
int len = 0;
byte[] b = new byte[1024];
ServletOutputStream sout = response.getOutputStream();
try {
while ((len = in.read(b)) > 0) { //图片输出的输出流 sout.write(b, 0, len); }
sout.flush();
//输入完毕,清除缓冲
response.setContentType("text/html");

//sout.println("<script language="+"javascript"+">window.open ('http://192.168.1.9:9001', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')"+"</script>");
sout.flush();
out.clear();
out = pageContext.pushBody();
//response.sendRedirect("http://192.168.1.9:9001/");
sout.close();
in.close();
} catch (Exception e) {
in.close();
sout.close(); e.printStackTrace();
}
%>

解决方案 »

  1.   

    补充,在这个JSP页面写的JS,貌似不能执行
      

  2.   


    <%
    FileInputStream in = new FileInputStream("d://house_1.jpg");
    int len = 0;
    byte[] b = new byte[1024];
    ServletOutputStream sout = response.getOutputStream();
    try {
    while ((len = in.read(b)) > 0) {//图片输出的输出流sout.write(b, 0, len);}
    sout.flush();
    //输入完毕,清除缓冲
    response.setContentType("text/html");
    %>
    <script language="javascript">
    //此处放你的js代码
    </script>
      

  3.   

    js代码当文本输出即可,没必要放在java脚本中
      

  4.   

    恩,我用你的方法测试了,JS脚本放在页面中,但是图片输出后,JS还是得不到执行,以下是我的测试代码: <body> <%
    FileInputStream in = new FileInputStream("d://house_1.jpg");
    int len = 0;
    byte[] b = new byte[1024];
    ServletOutputStream sout = response.getOutputStream();
    try {
    while ((len = in.read(b)) > 0) { //图片输出的输出流 sout.write(b, 0, len); }
    } catch (Exception e) {

    }
    sout.flush();
    out.clear();
        out = pageContext.pushBody();
    //输入完毕,清除缓冲
    response.setContentType("text/html");
    %>
    <script language="javascript">
    //此处放你的js代码
    window.open ('http://www.163.com', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
    </script>
    </body>