From the small demo in the previous section, we figured out how to connect with ePRO and the ePRO payment process. In this section we'll do the payment page and import the bank icon in the page.
1. Storage Bank icon
The bank icon generally does not always go to load, because this writing is dead, there is no need to go to the payment page every time to load the bank icon, so performance will be affected. This reminds us of the previous loading of the first page data, in fact, with that truth is the same, we can start the project when the bank icon resources loaded into the application, after the use of the directly in the application domain to take the line. So as usual, we loaded the bank icon in the listener .
The bank icon will be provided to us by the official, then we need to do is to put these icons in a folder under the project, I was placed in the webroot/files/bankimages, the names of these icons are strictly according to the official requirements of ePRO name, as seen in the previous section, ICBC is named Icbc-net.gif.
The idea of loading icons is as follows:
1) First get all the names of all the icons from the specified directory, and filter out unneeded files , this filter is very important, because if there are some extra files or hidden files, we have to get to, and then the foreground display when there will be some strange things, so we just use the useful icon.
2) Next we get the icon names and put them in an array or collection and then save the array or collection in 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 wrote earlier.
1.1 Get Icon name
We add the code that gets the name of the icon in Fileuploadutil:
@Component("FileUpload") Public class fileuploadutil implements FileUpload { //Omit the original code ... //@Value means to find id= "prop" Bean in the Beans.xml file, which reads the properties configuration file by annotation and reads it in the corresponding configuration file . @Value("#{prop.basepath+prop.bankimagepath}")PrivateString Bankimagepath; PublicString[]Getbankimage() {string[] list =NewFile (Bankimagepath). List (NewFilenameFilter () {//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);//To achieve the filtering effect of file by suffix name //return True to the list, return to false filter out returnName.endswith (". gif"); } });returnList }
We load the Public.properties configuration file and look at the contents of the configuration file:
basePath=E\:\\web\\apache-tomcat-8.0.26\\webapps\\E_shopfilePath=\\filesbankImagePath=\\files\\bankImages
The reason why there is a basepath is to facilitate the expansion, and later modified basepath do not need to move. We continue to look at the method above, the new File(path).list()
method is to get all the file name in the path, but new File(path).list(FilenameFilter filter)
with the filtering function, you can filter out the unwanted files, only return the desired file into the array. FilenameFilter
There is only one method in the interface accept
, so we can use the inner class to determine if it is a. gif suffix file.
1.2 Save the icon name in the Application field
Here we store the array of icon names just saved in the listener in the application domain, these methods have been introduced before, do not explain more, look directly at the code:
//@Component//listener is a component of the Web layer, which is instantiated by Tomcat and not by spring. cannot be put into spring. Public class Initdatalistener implements Servletcontextlistener { //Omit other code ... PrivateApplicationContext context =NULL;PrivateFileUpload FileUpload =NULL;@Override Public void contextinitialized(Servletcontextevent event) {context = Webapplicationcontextutils.getwebapplicationcontext (Event.getservletcontext ());//Put an array of storage bank pictures into application and load the project when it startsFileUpload = (fileUpload) Context.getbean ("FileUpload"); Event.getservletcontext (). SetAttribute ("Bankimagelist", Fileupload.getbankimage ()); }}
2. Payment page Display
Let's take a look at the code for this piece of bank.jsp about the bank icon, as follows:
There is also a piece of information showing the order, from the following code can also be seen from the session to take our previous backup of the order information, the original information when the user confirmed the order jumped to the payment page has been destroyed.
3. Test the effect
Let's test how the payment page looks, as follows:
OK, the payment page appears normal, the following to complete the payment function, that is, the last section of the servlet written by the demo function, but now put in struts, and may have to consider some other problems, the next one to write it ~
(Note: To the end to provide the entire project source code download!) Welcome to our collection or attention)
Related reading: http://blog.csdn.net/column/details/str2hiberspring.html
-Willing to share and progress together!
-More articles please see: http://blog.csdn.net/eson_15
"SSH Online Mall project Combat 22" get the Bank icon and payment page display