-1

And how can I make it work?

<%

    class thing {

        public String doit () { 
            return "doing it";
        }

    }

    request.setAttribute ("thing", new thing ());

%>


<body>
    ${requestScope.thing.doit ()}
</body>

I don't have the freedom to create a separate compiled class. It must be inline.

Thanks.

Rex the Strange
  • 133
  • 1
  • 6

1 Answers1

0

You don't need to the request because the scriptlet is server side and a better use will be

<%
        public String doit () { 
            return "doing it";
        }
%>


<body>
   <%
doSomething();
%>
</body>

With this you call your function. But in the end this is a very Bad Practice to use scriptlets. It's hard to debug. Hard To read, etc, etc. Read a lot of good answers in SO Like this one

Gatusko
  • 2,503
  • 1
  • 17
  • 25
  • Thanks, but not really an answer to my question. I didn't ask for another way of doing it (which I know and I know about the "Bad Practice" of using scriptlets but it's not really my decision to make). – Rex the Strange Jul 06 '18 at 20:34