Learning Process of a Jsp beginner (6)

Source: Internet
Author: User

A learning process for beginners of jsp (preferred for SUN Enterprise Applications) (6)

TheUnforgiven


Chapter 6 bar chart

In the process of coding, I found more and more problems, such as Java, SQL, Html, and JavaScript, my research on these seemingly small issues has accumulated practical experience, at least not just on paper.
At this time, my leadership asked me to do something to repair computer faults on the LAN. This is actually a message board function. I just did some exercises before, so I did it easily. Then I thought I should make a statistical statement to count the number of repair tasks completed each month in a year. If the table is displayed, it is too simple. It is better to create a dynamically generated column chart, I suddenly had this idea.
Start immediately. First, check the information and find out that Java is related to drawing. the awt package, because the graph I conceived is only composed of rectangles, the methods used are as follows: fillRect, drawRect, setColor, setFont, and drawString. I soon found a problem: how to display this graph on the page is a big problem, so let's look for an example.
With the help of a colleague who has studied the Postgraduate Java course, you can see the following code in <body>: <applet code = "Picture" height = "400" width = "400"> </applet>: Run this file. However, this method has two drawbacks: 1. It downloads Picture directly from the server. class, which generates images on the client. Therefore, the client must have a java environment, such as j2re; 2. Currently, most browsers are helpless or forcibly kidnapped (here I seriously despise 3721 and one called "World search) install plug-ins that prevent small windows and ActiveX controls-even XP SP2 integrates this function-and this function is also effective for <applet>.
After giving up the first method, I found the second example on the Internet. The second example made me very strange, and the code was written directly in one. in jsp (preferred for SUN enterprise-level applications) files, open the file to display images. The attribute of this image is actually this. the name of the jsp (preferred for SUN Enterprise Applications) file. After reading the code for a while, I didn't quite understand it. I started to look at the third example.
The third example is in line with my thinking: the inventory file is saved according to the passed path name. Then, the page is displayed through Display images. I implemented the work in this way. The code for this class is as follows:
-------------------------------- Picture. java ------------------------------------
// This bean is used to draw a bar Statistical Chart.
Package ringz. javabeans;
Import java. io .*;
Import java. util .*;
Import com.sun.image.codec.jpeg .*;
Import java. awt. image .*;
Import java. awt .*;

Public class PictureBean
{
BufferedImage image;
Private String fileLocation;

Public void setFileLocation (String fileLocation) // fileLocation is the image path, for example, "D: \ a \ B \ c.jpg"
{
This. fileLocation = fileLocation;
}

Public void createImage (String fileLocation)
{
Try
{
FileOutputStream fos = new FileOutputStream (fileLocation );
BufferedOutputStream bos = new BufferedOutputStream (fos );
Required imageencoder encoder = required codec. createJPEGEncoder (bos );
Encoder. encode (image );
Bos. close ();
}

Related Article

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.