0

How to send data to HTML page from Java code

I have made a html page having two text boxes to take two integer inputs. I send those two integers to Java code using servlets and perform addition of the two. Now I want to display the calculated result on html page. How can it be done??

5th Oct 2019, 12:51 PM
Leman Kirme
Leman Kirme - avatar
7 Respostas
+ 3
Anton Böhler No he is not confusing. He is asking right question. Leman Kirme You can use servlets with JSON for this. But if you don't know JSON then there is a method in servlets that is request.sendRedirect() which will redirect to other html page with result. But for that you have to use JSP not html.
5th Oct 2019, 2:31 PM
A͢J
A͢J - avatar
+ 1
are you confusing Java with JavaScript? 😅 If it's JavaScript you can do 'document.getElementById("id")', id is the id of the element you want to get from your html then you can set the contents of the element with the attribute 'innerHTML'
5th Oct 2019, 12:55 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Leman Kirme That's why I said use JSP. So you can easily print if you know the JSP well. But I will suggest to use JSON with servlets so you can print on html itself using JavaScript.
5th Oct 2019, 3:37 PM
A͢J
A͢J - avatar
5th Oct 2019, 4:04 PM
A͢J
A͢J - avatar
0
A J request.sendRedirect() will redirect to another HTML page but how to print result on that page May u help me with a sample code
5th Oct 2019, 2:38 PM
Leman Kirme
Leman Kirme - avatar
0
A J I don't have much knowledge about JavaScript. Please help me with the JSP code to print 🙏
5th Oct 2019, 3:44 PM
Leman Kirme
Leman Kirme - avatar
0
A J Tysm... This solved my query
5th Oct 2019, 4:07 PM
Leman Kirme
Leman Kirme - avatar