Java Web practice topic-image management

Source: Internet
Author: User

A large number of images may exist in a website. Some images are the same for all webpages, such as the logo of a webpage and images on the home page. These images are like common HTML files, the processing of these images is usually done by the Web editing tool, that is, it is usually done by the artist. The following HTML Tag is used: SRC specifies the file path and uses the relative path, generally, we create a folder named images in the Web application to store all the images. Generally, the processing of these images does not need to be managed by Java programmers. There are also some pictures that need to be considered by programmers. For example, a website has a message board. When leaving a message, users can choose an emoticons. The emoticons are very simple pictures, each user will choose one message. If not selected, the system will also give a default message. Here, images are used to share so many images, no matter how you choose them. The common practice of processing such images: record the image number while recording the message, so that the image itself can be searched based on the Image number when displayed. In another case, if the system wants to save photos of all users, these photos are different for different users, at this time, if the above method is used, the image can also be used to complete the function, but the management is not convenient, and the database should be used in a more reasonable way. Generally, images are uploaded to the server and stored in the database. When necessary, they are extracted from the database and displayed. The following describes the two image processing methods. Manage images through pathAnd so on. (1) To generate a path, select a single button in the HTML file for the user to choose from. For example, the following code shows 20 selected expressions and uses the file name naming method described above. Select emoticon: <br> <input type = "radio" name = "Mode" value = "01"/> <input type = "radio" name = "Mode" value = "02"/> <input type =" radio "name =" Mode "value =" 03 "/> ... Note that mode is the name of a single-choice button. In the processing file, the information selected by the user will be obtained based on the name. The value corresponds to the value of an option. If you choose the first image, the value of the single-choice button is 01. The IMG label is used to display emoticon images. Then obtain this parameter in the processing file, save it to the database, and obtain information. You can complete the following code: request. getparameter ("mode"); for how to store data in a database, see the database section in this book. (2) generate an image based on the path information. First, you need to obtain the path information of the image to be displayed from the database. For the database access process, see the database section in this book. Assume that the obtained information is saved in Str. Generally, the information is saved to the request first, and the following code is used: request. setattribute ("Mode", STR); then it is displayed on the page. The file name needs to be determined based on this path. Therefore, the file name part in the IMG tag must be determined based on this variable. The original format is: replace 01 with a variable and use the expression: the following code can also achieve the same effect: <% string STR = (string) request. getattribute ("Mode"); out. println (" or <% string str2 = (string) request. getattribute ("Mode"); %> . GIF "alt =" "/> the idea of using storage paths is very simple. Storing image information in the database is not necessarily all information, as long as the image can be determined, Then, the path of the image is displayed based on the information in the database. Store images through databasesTo store images in a database, you must use BLOB fields to store byte stream objects. Assume that we want to manage user information. To simplify the process, the user information includes the user name, user number, and photo. The table definition statement is as follows: Create Table user (userid varchar (10) primary key, username varchar (10), picture BLOB) describes how to upload, store, and display images. (1) the upload function of image upload files is provided in struts. First, you must create an upload interface. The corresponding code is as follows: <% @ page contenttype = "text/html; charset = GBK "%> <% @ taglib uri ="/WEB-INF/struts-html.tld "prefix =" html "%> <HTML>  

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.