From the small demo in the previous section, we figured out how to connect with Yibao and Yibao's payment process. In this section, let’s do the payment page and import the bank icons into the page.
1. Store bank icon
Bank icons generally do not always load because these things are dead. There is no need to load bank icons every time you enter the payment page, so that performance will be affected to a certain extent. This reminds us of the previous loading of homepage data. In fact, it is the same as that. We can load the bank icon resource into the application when the project is started. After that, it can be used directly in the application domain. So as before, we load the bank icon in the listener.
The bank icon Yibao official will provide us with, so what we need to do is to put these icons in a folder under the project. I placed them in WebRoot/files/bankImages. The names of these icons are strictly named according to the official names required by Yibao. As seen in the previous section, ICBC named it ICBC-NET.gif.
The idea of loading icons is as follows:
1) First, get the names of all icons from the specified directory and filter out unnecessary files. This filtering is very important because if there are some extra files or hidden files, we have all obtained them, and then some strange things will appear when the front desk displays them, so we only have useful icons.
2) Secondly, after we get the icon names, we put them in an array or collection, and then store the array or collection in the application field, it is obvious. The second step is implemented in the listener. The first step is that we can write a new tool class ourselves, or we can complete it in the fileUploadUtil class we wrote before.
1.1 Get the icon name
We add the code to get the icon name in fileUploadUtil:
@Component("fileUpload")public class FileUploadUtil implements FileUpload { //Omit the original code... //@Value means to search for the beans with id="prop" in the beans.xml file. It reads the properties configuration file through annotation, and then reads @Value("#{prop.basePath+prop.bankImagePath}") private String bankImagePath; public String[] getBankImage() { String[] list = new File(bankImagePath).list(new FilenameFilter() { //Test whether the specified file should be included in a file list @Override public boolean accept(File dir, String name) { System.out.println("dir:" + dir + ",name:" + name); //Use the suffix name to achieve the file filtering effect//Return true and put it in the list, return false and filter out return name.endsWith(".gif"); } }); return list; }We are loading the public.properties configuration file, and take a look at the contents in the configuration file:
basePath=E/://web//apache-tomcat-8.0.26//webapps//E_shopfilePath=//filesbankImagePath=//files//bankImages
The reason for a basePath is to facilitate expansion, and the basePath does not need to be moved if modified in the future. Let's continue to look at the above method. The new File(path).list() method is to get all file names in the path, but new File(path).list(FilenameFilter filter) has a filtering function, which can filter out unwanted files and only return the desired files into the array. There is only one accept method in the FilenameFilter interface, so we can use internal classes to implement it and judge whether it is a file with .gif suffix.
1.2 Save the icon name into the application field
Below we store the array of icon names that have just saved into the application field in the listener. These methods have been introduced before, so I won't explain them more. Let's just look at the code:
//@Component // Listener is a component of the web layer. It is instantiated by tomcat, not Spring. Can't be put in Spring public class InitDataListener implements ServletContextListener { //Omit other codes... private ApplicationContext context = null; private FileUpload fileUpload = null; @Override public void contextInitialized(ServletContextEvent event) { context = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); //Put the array storing bank pictures into the application, and load fileUpload when the project starts = (FileUpload) context.getBean("fileUpload"); event.getServletContext().setAttribute("bankImageList", fileUpload.getBankImage()); }}2. Payment page display
Let's take a look at the code of bank.jsp about the bank icon, as follows:
Another piece shows the relevant information of the order. It can also be seen from the code below that we took the order information we had previously backed up from the session. The original information was destroyed when the user confirmed the order to jump to the payment page.
3. Test the effect
Let’s test the display effect of the payment page, as follows:
Okay, the payment page displays normally. The payment function is to be completed below, that is, the demo written in the previous section using servlet. However, it is now put in Struts, and some other issues may be considered. Let's write it in the next section.
Original link: http://blog.csdn.net/eson_15/article/details/51452243
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.