Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

invoke a java function onSubmit of the form  RSS feed

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP page with a form inside of it. 'onSubmit' of the form, I want to invoke a java function with a value of the form.
I am adding part of my code here:

<form action="" id="hiddenform" name="hiddenform" method="post" onSubmit="<%getResponseValue(out.println("><script>this.ResponseType.value</script>"));%>">

<select name="ResponseType">
<option value="Default">Default</option>
<option value="Sucess">Sucess</option>
<option value="Failure">Failure</option>
<option value="Retry">Retry</option>

And here is my java function in the same file:

<%!String getResponseValue(String responseVal){
System.out.println("this is the responsevalue"+responseVal);
return responseVal;

Could you please let me know, why I am getting an error like below:
'void' type not allowed here
getResponseValue(out.println("<script>this.ResponseType.value</script>")); //[ /Admin.jsp; Line: 49]
1 error

Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look like you're confusing Javascript with Java.

First step is to stop using scriptlets. It would only increase the confusion. Write raw Java code in Java classes (e.g. servlets, javabeans, dao classes, etc) and use taglibs/EL to control the presentation flow.

Second step is to learn Javascript/HTML DOM properly. There are good tutorials available at

Just keep this in mind: Java/JSP runs at the server machine and produces a HTML/CSS/JS page, which is been sent from server machine to client machine, in the client machine the webbrowser will start to display HTML/CSS and run JS. Do a 'view source' in your webbrowser, you'll notice that there is no means of JSP/Java. All the HTML event handlers (the on* attributes) are only capable of running JS.
Author and ninkuma
Posts: 66678
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article should be helpful in understanding why what you are trying to do makes no sense.
I am Arthur, King of the Britons. And this is a tiny ad:
Rocket Oven Kickstarter - from the trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!