Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a new java application from scratch by cppweb

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to build a new java application from scratch in cppweb". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

How to create a new java application from scratch by cppweb

If the system has the java development environment installed (the JAVA_HOME environment variable needs to be set), the java compilation option is enabled when initializing the cppweb compilation environment. There is an example of a java project in the cppweb source code file. The path of the project directory is $SOURCE_HOME/webapp/jar, and the directory structure is as follows:

Bin: compile output directory src: project source directory

There is a simple application source file $SOURCE_HOME/webapp/jar/src/app in the project. The source code is as follows:

Package app;import webx.WebApp;import stdx.Required;import stdx.Optional;import webx.utils.DBConnect;import webx.http.HttpRequest;import webx.http.HttpResponse;class Request {@ Required ("user ID") public String user;@Optional ("user name") public String name;} class Response {@ Required ("error Code") public int code;@Optional ("error description") public String desc } @ WebApp.Path (value = "${filename}", access = "public") @ WebApp.Document (request = Request.class, response = Response.class, remark = "JAVA sample interface") public class JavaTest extends WebApp {public void process (HttpRequest request, HttpResponse response) throws Exception {Long msg = DBConnect.Select (Long.class, "SELECT?", System.currentTimeMillis ()); response.setBody (String.valueOf (msg));}}

There are two key comments in the above source file, which are as follows:

WebApp.Path applies path annotation, which has two attributes. The value attribute represents the final mapped interface path, and access represents the access permission of the interface (with values such as public, protect, private, etc.).

The WebApp.Document API document states that request is the metadata object of the request class, response is the metadata object of the response class, and remark is the interface name description. The application marked with this note will generate the API document, which can be viewed by accessing the http://localhost:8888/app/workspace/pub/apidoc.htm address.

After modifying the source code, go to the $SOURCE_HOME/webapp/jar directory and execute the make command to compile and generate the bytecode file corresponding to the application. Restart webserver to access the javatest address after compilation to view the execution effect of the application. The value attribute value of the WebApp.Path annotation ${filename} will be replaced with the lowercase of the specific class name (here, javatest).

In the actual development process, generally use the integrated development environment to develop web applications, when using the integrated development environment to compile cppweb applications need to include all the jar packages under the $SOURCE_HOME/product/jar directory. If it is a windows system, we recommend setting the $SOURCE_HOME environment variable. The following figure shows the configuration of our idea project:

If you need to run or debug the webserver service in idea, you need to comment out the JAVA_CLASSPATH configuration item in the startup configuration file $SOURCE_HOME/webapp/etc/config.lua. The startup class of the idea project is always webx.WebApp (the corresponding source file is $SOURCE_HOME/library/java/webx/WebApp.java).

This is the end of the content of "how to build a new java application from scratch in cppweb". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report