0

I have a table in which a column has buttons . on clicking this button the function should be called and the function should inturn call a scriplet method by passing parameters from the function.This should be in the same jsp page.

I have the rough code here:

<%

public String manager(String abc, String sbc){

}
%>

<html>
<head>
<script type="text/html">
function f1(){
id = document.getElementById("E1");
id.innerHTML("print");
}



</script>
<body>
<table>
<tr><td>numbers</td></td> status</td><td>check</td></tr>
<tr><td>1</td><td ID ="E1"></td><td id="E1" type="button" value="submit" onClick="f1()"></td>

</table>


</body>

</head>

</html>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
user903676
  • 319
  • 1
  • 4
  • 10
  • Please be more clear, couldn't understand wat u r trying to say – AmGates Aug 25 '11 at 10:36
  • Related: [How to use Servlets and Ajax?](http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax) @AmGates: non-native English readers would find you hard to understand as well with childish speak like "u" and "r". – BalusC Aug 25 '11 at 13:55

1 Answers1

3

Scriptlets contain Java code which is executed to generate the HTML page, at server-side.

JavaScript code is executed in the user's browser, seconds, minutes or hours later, at client-side.

To do that, you need to trigger an AJAX call from the JavaScript function to some servlet, which will execute the Java method.

Side note: JSPs are meant to generate markup, niot to execute business logic. Code your business logic in Java classes, used by a Servlet, then dispatch to a JSP which generates the markup. The JSP code should only use the JSP EL, the JSTL, and custom JSP tags. No Java code.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks for your suggestion.. How can i trigger an Ajax call from javascript to the servlet.. can i call the servlet in the same page – user903676 Aug 25 '11 at 11:22
  • Step back, and learn what AJAX is before trying to implement anything. Then see if it can solve your problem and how. – JB Nizet Aug 25 '11 at 11:34