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
You can’t use
JSPimplicit 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?.