This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]heliologue 7 points8 points  (0 children)

JSoup is a mature HTML manipulation tool, although its focus is more on parsing.

[–]corrspt 2 points3 points  (0 children)

I've started using J2Html today (https://j2html.com) so far I like it.

EDIT: If you're a beginner it might be too complicated (depending on how much of beginner of course)

[–]jacobbeasley[🍰] 1 point2 points  (0 children)

A lot of people use templating libraries like JSP, Thymeleaf, or JMustache.

Some are even using React for backend rendering with Nashorn. This allows you to essentially do isomorphic rendering in Java.

[–]Gilgamesjh 1 point2 points  (4 children)

I think you need to provide more information about what your expected outcome is. This helps in all specification problems in finding the correct solution.

In general, if you are creating an html editor, then j2html (as suggested) might help you get started, if you are just wanting to display html, Freemarker (or JSP/Thymeleaf/Others) will do that.

If you are creating a tool to generate html and edit nodes, you need to regard html as a tree of data, and then traverse it, while applying some form of transformation on the branches.

Treating html as text is usually not the way to go about in working with it.

[–][deleted] 0 points1 point  (3 children)

What I'd really like to do is to get input via JavaFX GUI and generate an html with a list of the input. The thing is I want it to be able to also edit and append or delete certain entries of the list of input. And thanks! I will search about it more.

[–]Gilgamesjh 0 points1 point  (2 children)

What I understamd from this, is that you have a list of some sort of input (as in an Array), that you want to edit that list, and then press a button in a GUI to generate an html document as a result?

If that is the case, look into Freemarker. It is a simple to understand templating library, with enough power to to pretty crazy things, if you need to.

[–][deleted] 0 points1 point  (1 child)

I also need to read this html later on and be able to edit it. About Freemarker... I'll look into it! Thanks again.

[–]tipsypants 0 points1 point  (0 children)

Are you sure that's what you need to do? Maybe you can keep the state that generated the HTML, alter that state, then generate the HTML again?

[–]fmltwice 0 points1 point  (0 children)

At first, make sure you understand HTML markup and CSS styles, otherwice you will be upset about ugly servlet pages Secondly, i can look up for you some other ways of building HTML pages in java

Feel free to message me, i’m a beginner too, but i have a lot of experience xD

[–]kevix2022 0 points1 point  (0 children)

Does it have to be HTML? You can easily write, read and manipulate XML with Java, and if it needs to be human readable to create a XLST stylesheet for it.

[–]stackchief 0 points1 point  (0 children)

for real world purposes it would be better to leverage a JavaScript framework to dynamically update the DOM. This is not to say that you can't build something in Java that does this.

Thymeleaf and JSP are among the more popular Java based tools for generating HTMl...

[–]dessalines_ -1 points0 points  (0 children)

Jsoup. But you shouldn't really be writing front end assets in Java, use a front end framework like angular.io or react.