foreword
When running the payment case Demo provided by Alipay, I encountered some problems. The Demo provided by Alipay is a JAVAEE project running with Eclipse. I want to use IDEA to run and see, and I am used to Mavne managing jar packages and SpringBoot projects. When starting the web project, I also encountered some problems. Some small problems encountered are hereby recorded. By the way, review the web project startup.
Case code address: computer website payment demo
1. Import project in IDEA
Instead of using the method of directly opening the project, use new->Project from Existing Source...
the method
Several times next, the middle page chooses the default configuration
Select the jdk version, the case provided is jdk1.7. I am using jdk1.8 here. Need to modify
2. Configure the Web project
Open the project structure, and then configure one by one. Just follow the picture
2.1 Modify Project
Modify the jdk version
2.2 modify modules
Here, the relevant configuration about Eclipse that comes with the project is deleted. Then configure your own. Just follow the steps
Add Web in modules, here is a very important point, that is, the configured web directory must be the corresponding file name in the project. The default generated is web, but the project uses Webcontent
It is very important here, it must be modified to be the same as the directory name in the project. The default is web
Since there is no dependency library configured, no dependency will be added when clicking at this time
2.3 Add Libraries
Here is to import the jar in the project. It is hereby stated that the jar package provided by this project is incomplete, and an additional jar package needs to be added, otherwise some interface calls in the code will fail, which will also cause the project to fail to start. The specific jar package is given in the follow-up process.
2.4 Modify Artifacts
Add the dependency library just added here
2.5 Add new dependent packages
If no dependency package is added, the code reports an error, as shown in the figure below. There should be a default jar package in eclipse. However, additional additions are required in the idea.
Put jsp-api.jar and servler-api.jar into the lib directory of the project. As for where these two jar packages come from, you can go to the official website to download them, or you can go directly to the installed tomcat directory to find them. I copied it directly from the library in tomcat.
The way to add a new dependent library is the same as 2.3, and then it needs to be imported into the project, the same as 2.4. In fact, you can also directly put these two jar packages into the lib package first. Then add all the jar packages at once.
After adding the new jar package, no error will be reported. If the error is still reported, please clear the cache of idea and restart IDEA.
3. Project configuration tomcat
The specific configuration process is abbreviated, you can refer to what I wrote before
configure tomcat
4. Start the project
When starting the project, an error may be reported about illegal characters or something. At this time, you need to modify the character encoding method. The method is very simple. There is an option in the lower right corner of the page, select GBK, and then select Convert in the pop-up box. Then select UTF-8 again, and then select Convert, so that this error will not be reported when starting the project.
5. Modify the parameters in the code
Write the public-private and private keys, IDs, etc. into the corresponding locations. For the following parameters, please refer to the Alipay case documentation.
6. Payment effect display
7. Problems encountered
1. Project report status 404?
I know that there is no web project without configuration. After searching for a long time, I finally found that when adding modules, the default web is produced, and the project is Webcontent. The two do not match. Need to modify web to Webcontent.
2. Illegal characters are reported on the page?
To modify the encoding method, the file-encoding in the configuration should also be modified as follows. The encoding method of the page is feasible according to the method of convert. See how people know.
3. The code on the page is popular?
The jar package in the project lacks jsp-api.jar and servler-api.jar . You need to put these two jar packages into the lib directory of the project, and then configure Artifacts