I wish to call a method in JSP onClick, the method is on the same JSP inside scriptlet.
How should I archive this?
<%@ page import="java.io.*,java.lang.*,java.util.*,java.net.*,java.util.*,java.text.*"%>
<%@ page import="javax.activation.*,javax.mail.*,org.apache.commons.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%!
    public String sendMail(String to, String sub, String msg) {
        String res = null;
        System.out.println("HI");       
        return res;
    }%>
<html>
<head>
<title>Send Email using JSP</title>
</head>
<body>
    <center>
        <h1>Send Email using JSP</h1>
    </center>
    <form>  
        <label>Email To</label><br />       
            <input type="text" name="to" /><br /> 
        <label>Subject</label><br />        
            <input type="text" name="sub" /><br /> 
        <label for="body">Message</label><br />
            <input type="text" name="msg" /><br /> 
        <input type="submit" onClick="sendMail( to, sub, msg )"/>
    </form>
</body>
</html>
Note
The methods name is "sendMail", It's called on submit button I want to do the whole code in JSP only.
 
     
     
    