[Original] Web server to subvert the traditional Web development model

Source: Internet
Author: User
Tags java web git clone
Jerry Server-official version 1.0.0 documentation

An article before, the idea now seems really not very clear, got a lot of criticism. However, there are pros and cons of criticism, so I think a lot more carefully, and finally clear what I want to do. Have the nerve to issue the official version of the document!

1. Reason

In the Java Web example, the current web system development model, for the web and server side of the data interaction and page rendering, there are two different:

    1. The first is to back-end processing, Jsp,freemark template engine flow, this development mode requires the front-end staff to do a static page to the backend to deal with some other work. This development model is still popular today, which is also the recruitment of Java Web Programmers require HTML, JS, CSS reasons. By now it's basically the development model, and note that this mode is not really a front-end separation!
    2. The other is to the front-end processing, the front end to complete the Web page rendering work. To know, the front-end processing can only use JS, some front-end JS template engine also has a lot, vue, no matter again fancy, the essence is still JS. Can not be ignored is that completely rely on JS processing front-end page is flawed, such as SEO problems.
    3. In general, there are advantages and disadvantages of both ways. If you are involved in the actual development of the first I said above, need to back end of the front page to deal with, then you can use Jerry to solve this part of the Division of labor, to achieve complete front-end separation.
2. Definition

Jerry is a tool that helps back-end engineers do just the back end, and front-end engineers only do the front end.

3. Thought

In simple terms, the previous pattern is to request the backend interface, which returns a page to the browser after the backend is processed. The front and back ends are not completely detached, such as with the back-end template engine (freemark,thymeleaf) or JSP. Why can't web development really be as real as the front-end separation like Android and other mobile developers?

The above development pattern is the backend provides the interface (that is, the URL), processed to get some data, and then through a series of template engine rendering, populate the data, and then return the finished HTML page to the browser. The flowchart is as follows:

Jerry's idea was to split this part of the process. the flowchart is as follows:

Perhaps you would say, what about cookies? How does the session stay? I want to say that the Jerry server will perform the agent's role quite seriously. The method, Cookie, and parameters of the client's HTTP request are sent to the service side intact. The response sent back by the server will also respond to the Set-cookie to the client. (I think of the cookie is more commonly used, if the lack of thinking, welcome correction.) In theory, Jerry's plan is workable.

4. Mode
    1. A completely true front-end separation, Jerry uses today's most popular JSON as an interface for front-end data interaction.

      For back-end engineers, only need to care about the implementation of the interface, no need to contact the front-end page, and even do not require to understand HTML,JS.

    2. What are the advantages of doing interfaces only? A set of interfaces for the web, Android, iOS platforms, which greatly enhance the scalability of software projects. Admittedly, there are still some sites that use back-end direct return HTML fragment development mode, which is very bad for software extensibility.

    3. For front-end engineers, the task context is clearer and more concise. Unlike the previous only need to do a good job of the page, more need to use Freemark and other processing dynamic interaction. This was done by a back-end engineer. Can be said to completely subvert the past. Make Web site development like Android development of the front and back-end distinct.

    4. If you already have a mature front-end separation scheme, you don't need Jerry, and if your back-end engineers need to write freemark,thymeleaf, then consider using Jerry to achieve a more thorough front-end separation.

5. Scene

You can use Jerry as a front-end server to deploy it in a real-world project.

If you really don't want to deploy Jerry online, you can go to the front-end developers to use Jerry during the development process.

The original front-end only static pages and then to the back-end to render the work to all let the front-end to do, and then on the line to write the Freemark grammar of the HTML file into the backend project.

5. Advantages
    1. Start FAST!

      Respond quickly, configure background monitoring, and respond in an unobstructed response time.

      First read the cache of various files, using Ehcache implementation.

      For back-end interfaces, use weighted load balancing.

      Time-consuming and response-independent operations, such as log monitoring, are all running on other threads.

      If you have other ways to speed up, please leave a message.

    2. Lightweight! Without too much reliance, most functions can be written on their own. All dependencies are as follows:

      • Netty
      • SLF4J + logback
      • Fastjson
      • Ehcache
      • Junit4
      • Freemark
    3. Self-brought monitoring system. The response speed of the page and the HTTP information are all over the top.

6. Engine

Jerry uses Freemark as the template engine. That is to say, the back-end engineers need to use Freemark to render the page, now become front-end engineers to use.

For example, the server-side interface:

{    "message": "响应成功",    "state": {        "message": "ok",    },    "data": [{        "time": "2018-04-25 13:25:07",    }, {        "time": "2018-04-25 13:25:07",    }]}

HTML page:

    message:${message}<br>    com: ${com}<br>    data[0].time:${data[0].time}

For other uses, please refer to Freemark Learning website: Freemark Development Manual

7. Monitoring

Monitoring system for each page and file response time and request information monitoring, monitoring frequency can be in the global configuration file custom configuration, the default is 10s.

For monitoring logs You can customize the output directory, the directory only supports relative paths (that is, only in the WebApps directory), and the Monitoring log format is JSON.

The monitoring page provided by default is located under the Webapps/manage project. Default access: HTTP://IP Address: 8888/manage

Background Monitoring Page Preview:

Monitoring System Operation Flow:

8. Load Balancing

Jerry caches all the static resources, and Freemark itself with the cache. The back-end interface for Freemark pages supports the use of weighted load balancing. If you want to experience weighted load balancing, you can set the cache time to 1. Then constantly refresh the page. Refer to the interface configuration for how to set up load balancing.

9. Global Configuration

The global configuration file is located in the Config directory and is read using the default UTF-8 encoding. Detailed configuration is as follows:

#开启端口port=8888#默认首页index=index.html#默认项目project=ROOT#全局404模板(webapps/)404=/template/404.html#接口配置文件名,要求内容为Jsonconfig=page.json#接口配置文件的编码js_charset=UTF-8#解析接口响应的编码jk_charset=UTF-8#请求接口超时时间mstimeout=10000#freemark文件编码fm_charset=UTF-8#监控刷新频率(毫秒/ms)monitor=10000#监控文件目录(webapps/)monitorLog=/manage/log.json#缓存:最大存储元素个数maxElementsInMemory=10000#缓存:最大发呆时间(秒/s)timeToIdleSeconds=120#缓存:最大存活时间(秒/s)timeToLiveSeconds=600#控制台日志级别INFO/DEBUGlevel=INFO

Jerry puts all the Web projects and pages under WebApps, and the server responds only to files in the WebApps directory.

    1. About global 404 templates, by default. However, customization is also supported.
    2. About the interface configuration file, default Page.json. You can customize it, but it must be JSON content and be located under the project root directory (such as Root/page.json).
    3. The encoding of the interface configuration file is the encoding format of the Page.json file when it is read. Default Utf-8
    4. The Freemark file encoding is the encoding that sets the processing Freemark file.
    5. Monitor the refresh rate. The minimum is 1s and the default is 10s.
    6. The cache above means that in a valid 600 seconds (10 minutes), if the cache is not accessed for 120 seconds (2 minutes) in a row, the cache is invalidated. Even if there is access, it will only survive for 600 seconds.
    7. When you want to view the running log, switch to Debug. Default info.
10. Interface Configuration

Take a look at the model document and explain below.

  [{"page": "Index.html", "id": "je", "Inter": [{"link": "Www.kuaidi100.com/query?type= Shentong&postid=3374107234608&id=1 "," Weight ": 1}, {" link ":" Www.kuaidi100.com/query?typ    E=yuantong&postid=801371015800473775&id=1 "," Weight ": 2}]}, {" page ":" Admin/index.html ", "id": "je", "Inter": [{"link": "Www.kuaidi100.com/query?type=shentong&postid=3374107234608&id=1 "," Weight ": 1}]}]  
Properties Description
Page The path to the HTML file.
Id The ID name.
Inter Back-End interface objects, you can define multiple implementations of load balancing.
Link The actual address of the back-end interface.
Weight Weights, for load balancing.

In the official version of Jerry, using Freemark as the template engine, a (freemark) HTML file can only have one configuration.

12. Some other problems 1,linux with Windows

In Linux to deploy the Jerry server, access files are strictly case sensitive. While Windows is not sensitive to case.

For example, when accessing/root and/root, in Windows It is possible that Linux is failing.

If you have other bugs in use, please leave a message on my Git or blog.

2, about encoding

Full project default UTF-8, but also provides configuration support customizations.

For HTML files that do not require syntax processing, there is no coding problem involved.

For HTML files that require syntax processing, configure the config configuration file uniformly.

If garbled, please check your configuration.

3, how to start

Please save the following 3 directories or files in git clone/download this project, and delete all of them:

    • /config
    • /webapps
    • Jerryserver-0.0.1-snapshot.jar

It can then be run at the console or command line java -jar JerryServer-0.0.1-SNAPSHOT.jar .

If the Linux system is running in the background, add one at the end & .

Then use the problem, in general, only need to put the Web project under WebApps, the project root directory new Page.json interface configuration can be.
The detailed parameters of the interface configuration are described above. Then use the Freemark syntax in the HTML page to get back-end data. Example:

API interface:

{       "message": "ok",       "data": [           {               "time": "2018-09-06 16:57:43",           }        ]  }

HTML page:

<p>    message:${message}<br>    data[0].time:${data[0].time}</p>
4, is not the building of Nginx wheel

The point is clear, No. Take a look at the following flowchart:

13. Update Log

2018/9/8: Fixed a bug where the interface data failed to resolve for the array.

2018/9/9: Upgrade the revision, mainly to simplify the interface configuration. Implements a policy for an interface configuration on a page.

Bind the interface and the page. The method, header, and body of the access page are the method, header, and body of the request interface.

Support for GET requests, post requests, and so on.

For the request body type, in addition to the Multipart/form-data format, binary binary stream (picture, etc.), the rest of the format is supported. The default UTF-8 decoding and encoding.

2018/9/10: Remove Jsoup dependency and use HttpURLConnection for network requests.

14, the end of the prohibition of patent application!

Also, thanks for your support!

If the use of problems such as bugs, please go to the following address comments, or join QQ group communication.

My blog: yueshutong.cnblogs.com/

github:github.com/yueshutong/jerryserver/

Gitee:gitee.com/zyzpp/jerryserver

Open source China: www.oschina.net/p/jerryserver

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.