invoking java scriptlet in JSP using HTML

前端 未结 5 1306
[愿得一人]
[愿得一人] 2021-01-16 10:50

I am trying to find a way to invoke a piece of java code within the JSP using HTML form

  
5条回答
  •  情歌与酒
    2021-01-16 11:11

    you cannot write a java method in scriptlet. Because at compilation time code in scriptlet becomes part of service method. Hence method within a method is wrong.

    How ever you can write java methods within init tag and can call from scriptlet like below code.

    
    
           
    
      
    
        <%
            invokeMe();
    
         %>
    
      <%!
           private void invokeMe(){
           out.println("He invoked me. I am happy!");   
         }
       %>
    

提交回复
热议问题