Java-ee to build WAP site image Publishing Unified format processing solution

Source: Internet
Author: User
Tags filter format client
j2ee| Solution | site

Motivation:
In WML, there are different restrictions on the format of a picture because of the different browsers that are supported. For example, Common m3gate, currently mainly support the BNG format, and some browsers support the format of JPG. But if the picture is not processed by oneself, for example, the image format is collected through the Web Capture tool, so it needs to be processed in a uniform format when publishing.
Here, because the individual has been engaged in the development of the Java EE, so in the release of pictures are using a servlet to release the picture, in order to solve the WAP in the face of this challenge, do some more in-depth research. The following is a sorted solution (already implemented) to complete the unified picture format when the picture is published.

Solutions:
In the Java EE Web application, the common specification is the servlet specification, Because the current mainstream application server supports Servlet2.3 specification, so the basic of this scheme is Servlet2.3 specification, use the filter character of Servlet2.3 to filter picture content, integrate picture format. Here is a specific solution (suppose the servlet used to publish the picture is GetImage):

    • Provide a front filter (imageprefilter)
      Configure the front filter in front of the getimage to intercept the client's request when the client accesses the image, and generate a new Servletresponse object to pass to GetImage.
    • Provide rear filter (Imagepostfilter)
      Configure the GetImage filter above to intercept the return result of GetImage, and convert the picture into a uniform format to the client according to the GetImage return result.
    • External implementation HttpServletResponse Class (Imagehttpservletresponse)
      Save the Web container httpservletresponse and getimage the servlet output to the response object, such as Cookie,header,contenttype.
    • External implementation OutputStream Class (Imageoutputstream)
      When the Imagehttpservletresponse class acquires OutputStream, it returns a imageoutputstream of its own definition, Imageoutputstream saves all binary data that is output in getimage this servlet (you can use Java.nio.ByteBuffer)

The following is a logical diagram of the entire system's invocation:


Here are some examples of how to use the ImageIO object to format a picture:

    • Reads a BufferedImage object from the input stream:
      Bytearrayinputstream bin = new Bytearrayinputstream (Outputstream.getbytes ());
      BufferedImage src = imageio.read (bin);
    • Using the Imageio.write method, the picture is converted to the specified format and written to the specified stream:
      Imageio.write (Bimage, "PNG", outs);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.