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 implement Web GUI with Java

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I would like to share with you how to use Java to achieve Web GUI related knowledge points, the content is detailed, logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.

How does Vaadin work?

In the previous screenshot, you can see a Java class on the left. This code runs on the server, such as Apache Tomcat, Eclipse Jetty, or any other servlet container.

You can use the API provided by the framework to create user interface (UI) components such as text fields, combo boxes, data grids, date selectors, upload fields, and so on. You can combine these components to build views (also known as pages or UI), place UI components vertically or horizontally using layouts, or use CSS to place UI components in any custom way.

In the previous example, we created aTextField and both aButton were added to VerticalLayout in a. Once the view is ready, you can expose it through URL using the @ Route annotation. In this example, we are using the http:// local host: 8080 / you @ Route ("hello").

The Vaadin application is a Java Web application. The framework provides a Servlet implementation (VaadinServlet) for you to handle HTTP requests and responses. The servlet scans the Java class marked with the @ Route annotation to display the correct view in the browser. The first time a Vaadin application is requested, Vaadin uses a lightweight JavaScript file as the client engine to respond. The engine is responsible for handling events in the browser and sending them to the server in the form of JSON messages. The request processed by the VaadinServlet and the JSON response are also returned to the client engine. The engine then updates the elements on the page that need to be updated, if any, based on this message.

If the client-server communication is a conversation, it looks like this: (the user clicks the button in the browser) the client engine: Hey VaadinServlet, the user clicks the button with ID 5. VaadinServlet: of course. Let me check if there are any click listeners on that button. Yes, there is one. Let's execute the listener. Done. A good client engine, it seems that the listener wants to add a notification with "thank you for clicking" text. Client engine: I will use the DOM in the browser to add notifications to the page.

So the above conversation is of course a kind of simplification, but you need to understand the relevant principles of this aspect.

Behind the scenes, Vaadin uses HTTP sessions to store the component tree. This contains the status of the UI. Such as which components make up the view and what their state is (enable / disable, title, value, etc.). This provides a layer of security worth mentioning. Because the UI logic resides in the server, it is not exposed to the attacker. Authentication is performed on the server. For example, if aButton is disabled (using setEnabled (false)), this is not just a decoration in the browser-the server does not run any logic in the click listener added to the unenabled button, thus preventing attackers from using the developer tools browser to change the enabled state or call VaadinServlet to simulate click events.

Can I use Vaadin for free?

Right. Vaadin is an open source framework released under Apache License 2.0. You don't need to buy anything to use it to build mature Web applications.

There are some business components that can increase productivity, but they are optional. For example, there is a visual designer and a CRUD component that can help you build views faster. You can try these components for free before you subscribe.

Is Vaadin a substitute for JSP and JSF?

Right. It can be used as an alternative to JSP, JSF, and even JavaScript frameworks such as Angular. Many Vaadin customers have successfully migrated from these technologies to Vaadin.

Does Vaadin support Spring and Jakarta EE?

Right. Vaadin has official integration with Spring and Jakarta EE (formerly known as Java EE). When you use Spring Initializr to create a new Spring Boot project, you can add Vaadin as a dependency. For Jakarta EE, you can download a simple Hello, World example that uses Jakarta EE. At the time of this writing, only Jakarta EE version 8 is supported.

These are all the contents of the article "how to use Java to achieve Web GUI". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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

Development

Wechat

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

12
Report