SAE uploading web apps (including using databases) tutorials and troubleshooting

Source: Internet
Author: User

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 access key and secret key are used in the MySQL database, that is, the user name and password to connect to MySQL, you can set down the JVM startup 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 such as Helloword to familiarize themselves with the process (open the app with 404 or 503 questions to explain later).

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 circle: 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:

PrivateSqlmanager ()throwsioexception{//reading configuration FilesBundle=NewpropertyResourceBundle (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 charactersjdbcdrive= "Com.mysql.jdbc.Driver"; Strcon= "jdbc:mysql://" + Dbhost + ":" + Dbprot + "/" +DBname;}

Now only part of the code, the full code download will be attached later.
3. Problems with uploading the app:

1. I 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 this  server matched or handled this   request. Contexts known to   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 

There are also reports that servlet is not a servlet, mostly because your JDK version is too high or your jar package conflicts with jars already in the cloud, 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

SAE uploading web apps (including using databases) tutorials and troubleshooting

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.