How to Refer Current Page Content in JSP

How to refer current page content in jsp?  I am making a program which add two number which are in textbox1 and textbox2 then when I click on add button sum of two number should be display in third textbox.
 

Assuming that the name attributes of your textboxes are textbox1, textbox2, and textbox3, and your form's name attribute is myForm:

In the page <HEAD> section:
<SCRIPT type="text/javascript">
     function add2 () {
         var base = document.myForm;
         base.textbox3.value = base.textbox1.value + base.textbox2.value;
     }
</SCRIPT>

In textbox1 and textbox2, add this attribute:
onBlur="add2 ()"
This means that the JavaScript function will be called whenever the user finishes entering data in either textbox.
 

It depends on what you're trying to do.

If you are doing something on the client side, refer to the field in
Javascript (which, BTW, has *NOTHING* to do with Java) as
document.formname.textname.value
(replace formname and textname with the names of the <FORM> and <INPUT type="text"> tags)

If you want to setup an element, do something like this in your JSP:
<INPUT type="text" name="myField" value="<%=textValue %>" >
where textValue is a Java expression that can be evaluated as a String.

If you want to retrieve the value of an element, use this in your servlet code:
String fldVal = request.getParameter ("myField");

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.