How to separate text and links from an input textarea using a jsp page? - html

I´m really bad at programming, and I´m trying to do a web aplication using html and jsp pages, the application have to allows the users to post things, and well that is the problem, because I can´t separate text and links from the textarea.
There is the method to post.
<div id ="post">
<form method="post" action="Validaciones.jsp" >
<textarea name="comentario" rows="4" cols="20" maxlength="140" id="coment" >
</textarea>
<button name="publicar" value="publicar">Publicar</button>
</form>
</div>
But so, when I do:
String texto = request.getParameter("comentario");
It return the parameter as a String, so if a put, "Hello visit my page: www.ducks.com", there is a way to know what is text and what is the link?
Because the aplication have to show the links as links, with the (a) tag.
Thanks for the help.

Dont use plain textarea.You need to use editors like CKEditor,TinyMce(to name a few).
These editors help to maintain the text formatting and save it into the database.So when you view this on another page you will be able to see whatever you had written earlier in the editor.Hence these editors are called WYSIWYG (What-You-See-Is-What-You-Get)
So use these editors in your page.

Use regular expressions
Pattern p = Pattern.compile("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0‌​-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$", Pattern.CASE_INSENSITIVE);
String toMatch = "this is a URL http://google.com";
Matcher m = p.matcher(toMatch);
With the url , use substring for the string.

Related

tinymce : how to convert raw html tags?

i used tinymce to allow people to write content. But now i wan't them to edit their own content, i need to use tinymce again.
My problem is in my database, this content is composed of html tags, and when i try to load the text in my tinymce textarea (in edit view), i've got the raw content eg <p> Hello my name is <em>John</em> [...] </p> . But when they written this content, it was with "wysiwyg".
I want to convert this raw html to wysiwig.
here a screenshot of the raw html
and i want it to be like this when they click on "edit my content" button :
I use this:
echo <textarea name="icerik" id="editor1" rows="10" cols="80">'.htmlentities($satir->icerik).'</textarea>;
I use "htmlentities" method in php to convert html code to wysiwyg. When you write that converted text between and , you can get what you want.
Assuming you're using PHP of course. If not, try to search like for example "htmlentities in asp.net" or wait for another answers.
tinyMCE.activeEditor.setContent('<span>html data from your database</span>');
Use this:
strip_tags(stripslashes('row html content'))

jsonp to create seo friendly code

Is there a way to get the JSON code to convert to text so Search engines can read the rendered code as normal text rather than json tags
sample Source Code
<div data-binding-id="repeat1" data-binding-repeat="{{manufactures.data}}" class="span2">
{{jsondata}}
</div>
I would like it to do the following:
<div data-binding-id="repeat1" data-binding-repeat="{{manufactures.data}}" class="span2">
I am now text so the search engines can read it correctly
</div>
Is this possible??
Cheers
Yes, it is possible. You just need something in back end that will set jsondata and something in front end that will render the page. Smarty for example.
You must say which language you are using.

Creating a welcome email via a program

I am trying to create a welcome email for my company. While I have the text bedded down, it does not display correctly in all email clients. One way to do this is to use a TextBox or paste the text in a shape in Word. The borders remaining constant, the text remains within those borders and looks better. Given that I have about 1000 such welcome emails (each with name and login credentials), is there any other way to create these emails on the fly?
If so, what would I use to create via a program? HTML, PHP?
Create and HTML template and insert the text from the textbox inside the HTML template string.
Something like:
<html>
<body>
<h1>Welcome #person#</h1>
<div>#bodytext#</div>
</body>
</html>
And then just replace "#person#" and "#bodytext#" before you ship it out.
That would even allow your collegues to edit the template if you allowed them to.
I have personally used formatting the email as HTML and then writing the HTML to format the text as needed.
You could even use String.Format to insert the data where needed (borrowing the html from Silas because I didn't feel like making my own)
email.Body = String.Format("<html><body><h1>Welcome {0}</h1><div>{1}</div></body></html>", <user name>, <body of email>);

HTML: Why might an input with type=hidden appear after </HTML> on a web page?

I just had a look at html of my twitter page as part of learning HTML. At the end of the page I can see a lot of state as the value of a hidden input tag (the value appears to be in json form).
I see no obvious form associated with this, and it doesn't appear in the html request.
I wonder if anyone might be able to guess how/why these inputs and their values might be used.
</body>
</html>
<input type="hidden" id="init-data" class="json-data" value="
{"scribeMetrics":0,"environment":"production","wtfOptions":
{"dismissable":true,"connections":true,"pc":true,"limit":3,"
disabled":false,"display_location":"wtf-component"}
........ and so on.
If you look at this javascript file, you see that the init-data element is used
var a=$("#init-data").val(),
b=JSON.parse(a),
c=$.makeArray(arguments);
b.moreCSSBundle?using("css!"+b.moreCSSBundle,d):d()}if($("html").hasClass("debug"))
//and so on
If you want to know, why they used a hidden field and not standard javascript variables, you have to ask the guys responsible for this at twitter themselves ;). I see no obvious reason and the minified code doesn't make it easier to understand what's going on.

How to fill an HTML form with CSS?

I have an HTML form with radio buttons, check boxes, text fields and drop down lists.
Since I want user to fill everything in my form, none of the radio buttons and check boxes are checked and the text fields are empty.
I would like to write a CSS file that will fill the form with answers (I don't want to change my HTML file).
Is this possible ?
I would appreciate an example or any other idea ?
Thanks !
No, it isn't possible. CSS is for style, not markup, and changing the contents of an input field requires modification of the markup.
It sounds like you might want to consider JavaScript, which can be used to alter the contents of any element, including form elements.
Javascript is your best bet. If you want to fill in -sample- answers, however, like 'First Name' in the text area what would be labelled "First Name: " you can do something like <input type='text' value='First Name' name='emailForm'> and the value attribute will be filled in when the page loads.
You can use jQuery to accomplish what you want quite easily, using CSS-style syntax.
Here's a sample form:
<form ...>
<input name="firstName" />
<input name="lastName" />
</form>
And corresponding jQuery/JavaScript:
$(function () {
$("input[name=firstName]").val("John");
$("input[name=lastName]").val("Doe");
});
Should be easy enough to extend to a larger and more complex form. You can easily use classes or ids on the elements and in the jQuery selectors, as well.
CSS is for designing and styling the webpage. Although its capabilities have been exploited to pull of many tricks it is not a fix-all solution. What you need to do is pull the data you need to fill and put it in your fields.
You can do this two ways:
Use a server side language like PHP/ASP.Net to pre-fill this information.
Use Javascript/Jquery/MooTools or some other framework to fill it on the client-side, picking up the data from the server.
If the information is static then it is very easy, because you can just put this info as a part of the HTML content itself.
If this answer doesn't work for you, add more information to your question.