in javascript calling function which in while has to call ja

I’m creating one page with two text boxes. When user enters the value in the box and then onclick submit button i make call to the one function. In that function, i’m getting those two values. Then i have to pass those values to one java function which will return result. Then i’ll display that result. i …

via Java Application Development Tutorial » Search Results » ajax:

in javascript calling function which in while has to call ja

I’m creating one page with two text boxes. When user enters the value in the box and then onclick submit button i make call to the one function. In that function, i’m getting those two values. Then i have to pass those values to one java function which will return result. Then i’ll display that result. i dont know how to do this. I have written code. But it end up with error.
<%@ page import="java.util.*,mypackage.JavaFile"%>


<br />sample script</p> <p>



Enter value1:


Enter value2





In compilation error value1 value2 are not resolved. Please help.
………………………………….

So you are getting confused by the fact that you JSP is server side code but javascript is browser side code. You need to actually submit the form via an HTTP POST and get the value1 and value2 values from the POST request body, then use them in your JSP java code.
………………………………….

You are mixing java with javascript – javascript code is run on the client side (ie: the browser) and java code is executed on your server. Different computers, different programming languages, totally different contexts.
You have to send the variables with a (ajax?) hit to the server, call your java function, return the response and the browser to capture the response and show it to the user
………………………………….

So you need to distinguish between client side JavaScript and server side Java. It would be simpler if you created two separate pages for this. On the first page you can create the form with its inputs and submit button. Let that form submit to a second page.
On the second page you can then attempt to get the values that were submitted from the client. There is no need to use JavaScript at all in this scenario.
To get the values submitted from the form in Java on a JSP page you can:
<%
String value1 = request.getParameter(“val”);
String value2 = request.getParameter(“val1″);

%> Now you can use the values in your Java method that you wish to call.

For more info: in javascript calling function which in while has to call ja

Java Application Development Tutorial » Search Results » ajax

in javascript calling function which in while has to call ja

Share this post:

Related Posts

Leave a Comment