A user enters text as HTML in a form, for example: I want to be able to output only a part of the string ( for example the first 20 characters ) without breaking the HTML structure of the user’s input. In this case: which renders as Is there a Java library able to do this, or a simple method
Tag: html
Automatically generate HTML pages in Java
I am developing a Java desktop application. I have a need to create HTML pages through my application. When the user clicks on View in Browser button a HTML page should be created with some details and shown it to the user. Is there a way I can do this? Is there are any resources I can use in this
How to make javax Transformer output HTML (no self-closing tags)?
I’m using a javax.xml.transform.Transformer to convert an XML file into an HTML file. It can happen that a div will have no content, which causes the Transformer to output <div/>, which breaks rendering. I’ve searched and found that “You can change the xslt output to html instead of xm…
Returning ZipOutputStream to browser
I have an ZipOutputStream that I want to return to the browser. The experience I would like is that the user clicks an anchor tag, and then a file download prompt is displayed for the ZipOutputStream that I have. How do you get the ZipOutputStream back to the browser? Answer Just had to do this exact same thi…
How can I efficiently parse HTML with Java?
I do a lot of HTML parsing in my line of work. Up until now, I was using the HtmlUnit headless browser for parsing and browser automation. Now, I want to separate both the tasks. I want to use a light HTML parser because it takes much time in HtmlUnit to first load a page, then get the source and
Remove HTML tags from a String
Is there a good way to remove HTML from a Java string? A simple regex like will work, but some things like & won’t be converted correctly and non-HTML between the two angle brackets will be removed (i.e. the .*? in the regex will disappear). Answer Use a HTML parser instead of regex. This is dea…