I have a a JSP file in this format(two select tags)-
<%@ page import="mypackage.*" %>
<all the main tags>...
<form>
<select> options... </select>
<select> options... </select>
<input type="submit" value="submit" />
</form>
<textarea></textarea>
There is a java method inside “mypackage” which should take arguments from the <select> tags after clicking on submit.
The method returns a string which I want to output in the <textarea>.
How do I go about this ?
Thanks a lot guys.
I see that you are importing the mypackage.* classes into your JSP. Indeed, you could include Java code inside your JSP and call the class directly. Something like:
should be sufficient (but not good: the result should be escaped).
However, this code is not very maintainable and it can be done better (the answer of kaustav datta is one standard way of doing it).
It can be done in a more elegant way using the Spring framework’s MVC part: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html
It needs some configuration at the beginning and takes some time to understand, but when you got it, it is very nice.
In your case, a controller of the following form would be sufficient: