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??
7 odpowiedzi
+ 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.
+ 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'
+ 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.
+ 1
Leman Kirme Check this. Maybe this can help you
https://www.programmergate.com/pass-data-servlet-jsp/
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
0
A J I don't have much knowledge about JavaScript.
Please help me with the JSP code to print 🙏
0
A J Tysm... This solved my query