Search code examples
javaservletsscriptlet

Invoking class object method via scriptlet in servlet


I have a servlet and I want to run .java code through scriptlet. I have a simple class in Temp.java.

package pack;

import static java.lang.System.out;

public class Temp {

    public static void main()
    {out.println("trololo");

    }

}

And I want to invoke main method via scriptlet in index.jsp

<body>
    <%@ page import="pack.*" %>

    <%
    out.println("whatever");
    Temp temp = new Temp();
    temp.main();
    %>

</body>

What I have to do to make main function work after invoking via scriptlet? Printing "whatever" works, but main function doesn't print anything.


Solution

  • It will print on console, check logs

    you imported

    import java.lang.System.out;
    

    which is standard output, so check your stdout log

    Use JSTL instead