user1673627
user1673627

Reputation: 271

JSP Function Run Error

I have written the following jsp code in a jsp page for testing

<%!
    public String sayHello(String myName)
    {
          out.println("Hello Java"); // this line shows error
          return "Hello"+myName;
    }
%>

<%
  String str="William";
%>

   <%=sayHello(str)%>

If i remove the following line the page runs without error

         out.println("Hello Java");

Again, if i run a jsp file with only the following line included (not above codes) then also it runs well

         out.println("Hello Java");

Please help me where am i doing mistakes

Upvotes: 0

Views: 69

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94653

You can't use JSP implicit objects in methods. In order to access implicit object in custom methods, you have pass the reference of implicit (JspWriter) object to the method but use of Java code in JSP is highly discouraged.

Fore more information read wiki and How to avoid Java Code in JSP-Files?.

Upvotes: 1

Related Questions