tags:

views:

46

answers:

2

I am developing a Java project in which I will take the text from a user in a textArea and generate an HTML page with that text.

I want to allow the user to add links in the generated HTML Page. As I am taking the page contents from the user, I also need to take the link name and the URL from the user.

How can I provide this functionality?

+1  A: 

This is a bit vague ...

You don't say if you also somehow know where in the text the links need to be generated. If you don't, your problem is not solvable.

If you do, then I guess you just need to add some logic that tests if the current location in the output stream somehow corresponds to one of the locations where there should be a link, and generate the link.

The syntax for a HTML link can be found wherever, and I would assume you know it already, but just to be complete it looks like this:

<a href="http://www.example.com/"&gt;link to example.com</a>

Replace the part inside the quotes with the reference, and the text between > and < with the link name.

unwind
A: 

You'll need a database to store the links. Unless you want to show them only once.

String links = request.getParameter("textArea_name");
// then save it on your prefered database

To show it you can then load it from the database and just output them.

fmsf