Transferred from: http://blog.csdn.net/baiyuliang2013/article/details/24725995
SAE uploading web apps (including using the database) tutorials and questions :
recently due to job requirements, the need to use the SAE platform, but in the use of the process encountered a lot of problems, such as how to upload applications, upload application is not open, MySQL connection, and so on, and cloud bean billing problems, combined with personal experience, will be in this post to answer.
1. Upload Web App
first of all, use the SAE platform need to register their own account, this will not say, and then go to my home page, you will see:
Click Create App:
level Two domain name is defined by itself, composed of numbers and letters, not less than 4, the application name is generally the same as the project name you upload, the following development language select Java, and then appear:
This is a different level of the JVM at the expense of information, if not particularly large projects generally choose the economic version, the number of JVM Select 1, then the JVM opened an hour, only deducted 5 cloud beans, after closing, no longer billing, click the bottom of the app after the creation of the app will go to the list:
Click on the project name to go to the app's details screen:
The top of theaccess key andsecret key is used in the MySQL database, that is, the user name and password to connect to MySQL, down can be set to start the JVM shutdown, restart, etc., click on the left menu bar "code Management", then:
Click here to create a version, generally the first version of the 1, after the creation of the version is complete:
Click on the right side of the action-upload war package, as to how to put your project into a war package, you do not need me to say, click Upload OK, the first version of the successful creation, at this time you first see if your JVM is turned on, and then click on the project connection to see if the deployment is successful, Beginners can write a simple Web project like Helloword to familiarize themselves with the process, (open the app 404 or 503, and put it on the back.).
2, using MySQL database
a Web project with a complex point needs to be supported by a database, so how do you take advantage of the MySQL database provided by SAE? First in the Application Details page, click on the left menu service Management-mysql:
then click Initialize MySQL,
then we manage MySQL, and the MySQL interface will appear, which is similar to our local operation:
a few things to note:
1. Database name: APP_ project name, this is not modifiable, so your code or configuration file in the database name should be changed to the same as this;
2. Database connection address, at the top of the circled place: w.rdc.sae.sina.com.cn:3307
(address and port number);
3. Connect the database user name and password (mentioned above):access key and secret key.
As for the database connection code, presumably everyone is more familiar with, can use the most original code, can use the configuration file can also use the framework, below I put my
A Web application to connect to the database code for reference:
The first is the configuration file:
dbhost=w.rdc.sae.sina.com.cn
dbport=3307
Dbname=app_neteasy
Dbuser=mwmk40zyk0
Dbpassword=mi3hxh2212h3zz1lx5wklzw4wji3lxiklmkx1wlm
Here's how it's implemented:
Private Sqlmanager () throws IOException
{
Reading configuration Files
bundle = new propertyResourceBundle (SqlManager.class.getResourceAsStream ("config.properties"));
This. Dbhost = getString ("Dbhost"); Read Host name
This. DBname = getString ("DBname"); Read user name
This. Dbprot = getString ("Dbport"); Read Port
This. DBuser = getString ("DBuser"); Read User
This. DBPASSWD = getString ("Dbpassword"); Read Password
Setting the MySQL database driver and connection characters
jdbcdrive = "Com.mysql.jdbc.Driver";
Strcon = "jdbc:mysql://" + Dbhost + ":" + Dbprot + "/" + DBname;
}
In fact, this is not the same as the local database connection method, just change the database connection address and port number and user name and password,
only part of the code is posted, and a full code download link will be attached later.
3. Questions you encounter when uploading your app:
1. Do not know how to create the application and upload the deployment of the application has been explained in detail;
2. After uploading, open the application report 404,503 and other errors such as:
Error 404-not Found.No context on the this server matched or handled this request.
contexts known to this server is:
- /1/neteasy---> c.s.s.w.saewebappcontext{/1/neteasy,file:/data1/jetty_work/719/neteasy/ Jetty-0.0.0.0-11343-neteasy.war-_1_neteasy-any-/webapp/},/data1/www/htdocs/719/neteasy/1/neteasy.war [Failed]
- /2/neteasy---> c.s.s.w.saewebappcontext{/2/neteasy,file:/data1/jetty_work/719/neteasy/ Jetty-0.0.0.0-11343-neteasy.war-_2_neteasy-any-/webapp/},/data1/www/htdocs/719/neteasy/2/neteasy.war
- / NETEASY/2---> c.s.s.w.saewebappcontext{/neteasy/2,file:/data1/www/htdocs/719/neteasy/2/},/data1/www/htdocs/ 719/NETEASY/2
and there 's a servlet that's called servlet is not a, this is mostly due to the fact that your JDK version is too high or your jar package is in conflict with a jar already in the cloud, the workaround:
After exporting your project to the war package, open it with a compressed package, delete the Servlet-api.jar contained therein, and then upload the war package;
3. Not connected to the database, this is basically your code problem, or your code itself is a problem, if the local run is very shunliu, but is not connected to the cloud database, it is probably your database connection address, port, and user name password is wrong, please carefully check
Note the point:
1. When uploading the Web application, the first thin body, that is, delete unnecessary jar or JSP or Java files, can avoid jar conflicts can also save space (SAE stipulates that a project maximum of 100M);
2. Create an application, generally only need to create two versions on it, unless it is necessary, the first version of the non-tube (if only one version is not allowed to overwrite, so at least two versions), the second can update the iteration of your application (direct upload overlay);
3. Cloud Bean Billing, each JVM 5 cloud beans per hour, set up automatic recovery, will be in the application 2 hours without access to automatically hibernate, so do the test of children's shoes, in the absence of the time can be closed, has saved the cloud beans, through the real-name certification can be additional 2000, enough for a while ...
Here is the project file for my web app and the information returned after connecting to the database:
Finally, I enclose the demo of this project, which contains the key code for connecting the database:
http://download.csdn.net/detail/baiyuliang2013/7269897