SSH Framework Online Mall project 22nd War Bank icon and payment page display _java

Source: Internet
Author: User
Tags ssh tomcat

From the demo in the last section we figured out how to dock with Yeepay and the Yeepay payment process. In this section we'll do the payment page and import the bank icon in the page.

1. Store Bank icon

The bank icon will not always go to load, because these things are dead, no need to enter the payment page every time to load the bank icon, so performance will be affected. This let us think of the previous loading data, in fact, with that truth is the same, we can start when the project will be the bank icon resources loaded into the application, then used directly in the application domain to take the line. So like the original, we load the bank icon in the listener.
The bank icon is available to us, so what we need to do is put the icons in a folder under the project, I put them in the webroot/files/bankimages, and the names are strictly based on the name of the official Yeepay, as seen in the previous section, ICBC is named Icbc-net.gif.

The idea of loading icons is as follows:
1 first gets the names of all the icons from the specified directory, and filtering out unneeded files, this filtering is important because if you have some extra files or hidden files, we get them, and then there's something weird going on at the front desk, so we just need a useful icon.
2 Next we get the icon names and put them in an array or a collection, and then we save the array or collection to the Application field.
Obviously, the second step is implemented in the listener, and the first step is that we can write a new tool class ourselves, or we can do it in the Fileuploadutil class we've written before.

1.1 Get Icon Name

We added code in Fileuploadutil to get the name of the icon:

@Component ("FileUpload") Public
class Fileuploadutil implements FileUpload {
 //omitting the original code ...

 @Value means to go to the Beans.xml file to find the id= "prop" Bean, which reads the properties configuration file through annotations and reads the @Value in the appropriate configuration file
 ("#{prop.basepath+ Prop.bankimagepath} ")
 private String Bankimagepath;

 Public string[] Getbankimage () {
 string[] list = new File (bankimagepath). List (new FilenameFilter () {

  // Tests whether the specified file should be included in a list of files
  @Override public
  Boolean accept (file dir, String name) {
  System.out.println ("dir: "+ dir +", Name: "+ name";  
  Through the suffix name to achieve the filtering effect of the file
  //Return is really put in the list, return false filter back
  name.endswith (". gif");
  }
 );
 return list;
 }

We loaded the Public.properties configuration file and looked at the contents of the configuration file:

Basepath=e\:\\web\\apache-tomcat-8.0.26\\webapps\\e_shop
filepath=\\files
bankimagepath=\\files\\ Bankimages

The reason why there is a basepath is to facilitate expansion, and later modified words basepath do not need to move. We continue to look at the above method, new file (path). The list () method is to get all the file names in the path, but new file (path). List (FilenameFilter filter) with filtering function, you can filter out unwanted files, Returns only the desired file to the array. There is only one accept method in the FilenameFilter interface, so we can use the inner class to determine if the file is a. gif suffix.

1.2 Save icon name to application domain

Here we'll store the array of icon names in the listener in the application domain, which we've described before, and don't do much explaining, just look at the code:

@Component//listener is a component of the Web layer that is tomcat-instantiated, not spring-instantiated. cannot be placed in spring with public
class Initdatalistener implements Servletcontextlistener {
 //Omitting other code ...

 Private ApplicationContext context = null;
 Private FileUpload fileupload = null;

 @Override public
 void contextinitialized (Servletcontextevent event) {Context
 = Webapplicationcontextutils.getwebapplicationcontext (Event.getservletcontext ());  
 Put an array of stored bank pictures into application, and load
 fileupload = (fileupload) context.getbean ("FileUpload") when the project starts;
 Event.getservletcontext (). setattribute ("Bankimagelist", Fileupload.getbankimage ());
 }


2. Payment page display

Let's take a look at Bank.jsp's code for the bank icon, as follows:



  

There is also a piece of information to display the order, from the following code can also be seen from the session to take our previous backup order information, the original information in the user confirmation order jumped to the payment page has been destroyed.


3. Test the effect

Let's test the display of the payment page as follows:

Well, the payment page is normal, the following to complete the payment function, that is, the last one with the servlet written demo function, but now into the struts, and may have to consider some other issues, the next section to write it.

Original link: http://blog.csdn.net/eson_15/article/details/51452243

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.