Baidu Developer Center Bae new Java application

Source: Internet
Author: User
1. Apply for a developer account

First, register the Baidu account, and then apply to become a Baidu developer (the ID card must be verified by mobile phone ).

2. Create an application

Click Create application in the menu. We currently select a web application.

After the application is created, select the cloud environment in the left menu. For the environment type, select Java.

And create a new version. Enter 1 as the version number.

3. Start development in Baidu integrated development environment

Baidu provides eclipse-based plug-ins, which cannot support the latest eclipse version. We recommend that you download the one-click installation version of Baidu. Baidu document describes how to use the development environment. For details, see integrated development environment.

Open the Baidu integrated development environment, click Login to Baidu in the lower left corner of eclipse, and log on with your account. Click the logo in the toolbar, select import Bae project, and enter application and version.

Then select Java as the project language.

4. Solve project errors

The newly imported Bae project reports an error in eclipse. The problems view shows that the JRE environment is incorrectly configured and the Web runtime environment is incorrectly set.

A. Right-click Project properties-select javabuildpath, select Add library in libraries, and then select JRE system library.

B. next, convert the Java project to a Java Web project (convert the Java project in eclipse to a Java Web project). Note that if your tomcat version is 6, note that the version of the dynamic Web module cannot exceed 2.5.

Set the running environment of the Web application and create a new Tomcat server in the servers view.

C. Similar to A, add Server Runtime to Java build path and select Tomcat.

D. Modify hello. jsp and add the following code to hello. jsp:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

E. Deploy the project to Tomcat.

So far, all project errors are solved, and the running results are displayed.

5. Create a servert Test

Create a servlet named homeservlet. Eclipse automatically adds configuration information to Web. xml. The code for homeservet. Java and web. XML is as follows:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("}

Some code in Web. xml

<servlet>
<description></description>
<display-name>HomeServlet</display-name>
<servlet-name>HomeServlet</servlet-name>
<servlet-class>com.qiyadeng.HomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/HomeServlet</url-pattern>
</servlet-mapping>

After running tomcat, you can see that the following operation is successful, so that you can develop it like a common Java Web project.

6. Last

Jetty is used hundreds of times in the Java environment in Bae, instead of Tomcat. The advantage of Jetty is that it does not need to be restarted frequently, and the modified Code can instantly see the running result.

Submit code to Bae through SVN. If you need to make minor changes, you can directly modify the code using Baidu's online editing tool.

Original article, reprinted Please note:Reprinted from http://www.qiyadeng.com/

Link:Baidu Developer Center Bae new Java application

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.