function in jsp

Discussions

Web tier: servlets, JSP, Web frameworks: function in jsp

  1. function in jsp (1 messages)

    hi, if i am writing the function in jsp progrom when i compile that it compiles to servlet and can u plz tell me where this function will be there either in init() or service() method. It is asked me in interview i said it will go in service method but that person said that can u write method inside the method.

    Plz i am confuse.
    Sukhbir

    Threaded Messages (1)

  2. function in jsp[ Go to top ]

    It will neither be init() nor service(). You can't have function within a function in Java. When you declare a function in JSP (via the <%! %> tag) , it will go inside the class of the compiled servlet.

    e.g
    <%@ page language="Java" %>
    <%!
        public void myMethod(String message) {
    System.out.println(message);
        }
     %>


    will result in something like this in the generated servlet :

    public class test_jsp extends HttpJspBase {
     
        public void myMethod(String message) {
    System.out.println(message);
        }

        // Some other code ..
    }