將JSP在記憶體產生的圖片顯示到頁面_JSP編程

來源:互聯網
上載者:User

Imaging_ToWeb.jsp

<%@ page autoFlush="false"  import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*"%>
<%
    String ImageStr = request.getParameter("ID_Text");
    if(ImageStr==null || ImageStr.equals(""))
    {
        response.setContentType("text/html; charset=gb2312");
 %>
<HTML>
 <HEAD>
  <title>Http://www.lionsky.net</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 </HEAD>
 <body>
  <form id="Form1" method="post">
    <input type="text" id="ID_Text" name=ID_Text>
    <input type=submit value="GO">
  </form>
 </body>
</HTML>

<%
       }
       else
       {
        out.clear();
        response.setContentType("image/jpeg");
        response.addHeader("pragma","NO-cache");
        response.addHeader("Cache-Control","no-cache");
        response.addDateHeader("Expries",0);
        int width=300, height=100;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        //以下填充背景顏色
        g.setColor(Color.lightGray);
        g.fillRect(0, 0, width, height);
        String random="random";
        //以下設定前景色彩
        g.setColor(Color.BLACK);
        g.drawString("Http://www.knowsky.com",10,20);
        g.drawString("Author:Lion[lion-a@sohu.com]",10,40);
        g.drawLine(10,50,290,50);
        g.drawString(ImageStr,10,70);
        g.dispose();
        ServletOutputStream outStream = response.getOutputStream();
        JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
        encoder.encode(image);
        outStream.close();
    }

%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.