Get HTML element using JSP - html

I am new to Java EE. In my application, I have a HTML page containing a text area filled with some information.
I also have a form for the user. Once he submits the form, I use a servlet to process the information.
Finally I need to forward the Result from the servlet to the same HTML page and update it in the existing textarea.
I have done creation of HTML page, submitted the form to servlet.
I am now stuck on how to access the textarea in the HTML page to update my result.
I googled a lot but everywhere people forward the result of servlet to JSP page and create a fresh HTML page using "out" object.
I need to use the same textarea of my HTML page to update the result. Please help me on achieving this.
Thanks in advance.

There are two ways to do this.
Server-side rendering. You can re-draw the whole page, with a normal form submit. In this case you would put something in request scope in the servlet and then access that in the JSP when you draw the textarea. Note that you are not accessing the HTML textarea in the JSP - the JSP runs server-side code to generate HTML markup, but you are not accessing the browser DOM directly.
This might look like:
servlet: request.setAttribute("textareaContent", varWithTextareaContent)
JSP: <textarea>${textareaContent}</textarea>
Client-side rendering Instead, you could make an AJAX post request with jQuery (there are some plugins to help with this). In this case, your servlet would not forward to a JSP for HTML rendering - it would directly return a JSON object like {"textareaContent": ...} , and you would handle that client-side in your AJAX callback. In this case you would be accessing the textarea in the browser DOM directly, in Javascript (not JSP).

Related

How to get form data value from html and show on other html page

I am working on a html page with an input bar. How can I get the form data from this page to another html page with a iframe? Because I need to embed the search result from other site but I want to show on my site new page. I just guess should use iframe. But I don't know how to get data and add in page address field.
You have several options here:
1) If your form uses GET method, then all the text data from the form will be passed to next page (which is set up as an "action" attribute of the form) in URL (like www.example.com/?name=John&lastname=Doe). After that, you can extract data from this URL using code from this StackOverflow question and put it inside HTML element using Javascript as well like it is done here
2) Whatever server language you use, you can get query variables from there and put them to the page before sending it to the client. In case of PHP, check this example. NB: don't forget about security.
3) You can temporarily store text in localStorage API of the browser. Simply set the value before submitting the form and then get it on the next page.
iFrame would be inefficient and not needed here.

Contact form HTML, Returning a "Success" text in the .html file

i have this question and i can't find a solution. I'm pretty new in the programming. So..
my HTML file with the form is contact.html (straight html file)
The php code is in separated file. So, everythings work fine, but..
I want to have the return text for the "success" or "fail" in the in my html file (let's say under the submit button). Is it possible if it's not php file with html code, but straight html. And can you tell me what should I do?
I hope you understand me.
Straight HTML can't give different content conditionally.
You could get something that resembles what you describe by placing an iframe after the form and targeting it with the form. As solutions go, that's rather ugly.
You could use JavaScript to send the form data to the PHP file and then modify the DOM of the HTML document based on the response (Ajax), but that would be unnecessarily complex and violate the best practise of unobtrusive JavaScript.
The usual approach to this problem is to have a PHP file being the single entry point for all things relating to the form (it can keep parts of its logic or HTML in other files and include() them as needed) and have it decide, based on what input receives, if it should show:
The plain form
The form with error messages (and pre-populated with the user's incorrect submitted data)
The thank-you

Passing info in a URL to Sharepoint

I'm new to SharePoint but I was wondering if there was a way to pass variables from an external website to a SharePoint Web Part via GET.
e.g.
http://mysharepointpage.com/sites?name=Jay&age=23 does not populate my name or age input fields in the SharePoint Web Part.
Note: I had to remove the <form method="GET"> tags because I kept getting an error advising;
<FORM> tags are not supported in the HTML specified in either the Content property or the Content Link property. You can
remove the <FORM> tag, or use the Page Viewer Web Part, which supports the HTML <FORM> tag. The Content property can
be modified in the Rich Text Editor or Source Editor. More about the Page Viewer Web Part
When I click on the link it tells me;
Cannot display help.
Technical details: HC not found.
I'm guessing this is why I can't retrieve the data via URL.
A little more information as to how would be much appreciated.
Your query string looks correct:
Connect a Query String (URL) Filter Web Part to another Web Part
You will then need to implement javascript on the page to loop through all the keys and populate the form as required.
You should be able to use this link to help you with your javascript or please post what you are currently using: Getting query string values in JavaScript

Jsp - Assigning java variable with html input type text in same jsp page

I am trying to access one tag in index.jsp page to fetch it's value and access the input tag html value to one java variable value in the same jsp page (index.jsp)
I am trying to use the variable to connect to database and fetch other details in the same jsp page but that html input tag value is not assigned to java variable using request object and tried in many ways but was unable to assign the value...
is there any method/idea to assign the html input tag=text value to java variable in same jsp page without using JSLT?
Appreciate your response
I've decided to answer this because I've seen many green programmers get confused about this same exact subject for many HTML preprocessing languages (JSP in this case). I'm going to start off right away saying this is an XY problem, please see https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem .
After reading about what an XY problem is, the actual problem here ("X"), is that you can't access HTML elements at time of user interaction with JSP. JSP generates the HTML on the server. The HTML is then sent to the Client, the JSP code is done, and no longer able to do anything with the page because it isn't on the server. Now the HTML is on the client side and a user would enter the value you want. The server really has no access to the page anymore and it is impossible for the JSP code that generated the page to access the value.
Essentially, it is not possible to access an HTML element with JSP without doing this another very different way (sending value by ajax or something).

How can I post data (form) to html page and hijacking the data in the middle?

the site addres: http://www.ynet.co.il/YediothPortal/Ext/TalkBack/CdaTalkBack/1,2497,L-3650194-0-68-544-0--,00.html
fill the form with rubbish.
Hit 'Send'
the form post the data to another HTML without any parsing of the data i've just added
How do they do it?
A likely option is that they are using a content management system where "html" on the URL doesn't actually mean it's a static html file.
This may be out of left field, but I've certainly used the occasional JS function to grab everything in the header and either parse it or pass it to another script using AJAX.
I'll sometimes use this method in a 404.html page to grab the headers of the previous page, parse them out to see where someone was trying to go and redirect them.
That is, as annakata said, one of the numerous options available.
Edit based on clarified question:
Numerous frameworks can be configured to intercept an html request - for instance asp.net can be set to handle any given extension and an HTTPModule could do anything with that. It's really up to web server configuration what it decides to do with any request.
also: you don't really want to be saying "hijack"