illegal start of expression

I have  a method in JSP which checks if the value is null if it is null it returns ""

here is the code

<%
public string convert_null(string value){
   if (value==null || value.length()==0 || "null".equals(value)){
      return "";
   } else {
      return value;
   }
}
%>

I get this error

public string convert_null(string value){
illegal start of expression

Any help will be greatly appreciated

Thanks




royalcyberAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
Try it this way.

<%!
public string convert_null(string value){
   if (value==null || value.length()==0 || "null".equals(value)){
      return "";
   } else {
      return value;
   }
}
%>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrzCommented:
You tried to put your method into scriptlet. Code in scriptlets is put inside the   _jspService method. To see this look in Tomcat's work folder.
bloodredsunCommented:
As rrz has correctly pointed out, you need to use a declaration "<%! %>" instead of a scriptlet "<% %>" as shown here http://www.jsptut.com/Declarations.jsp. It is importatne that you understand the diference between a declaration, and expression and a scriptlet.

No points please, this is just a comment.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

royalcyberAuthor Commented:
Thanks you very much guys.

Also I would need to use this method in many jsp's. Now is there a way I can put this code somewhere and then try to reuse
bloodredsunCommented:
Either in a javabean or in another java class that you invoke in a scriptlet..
royalcyberAuthor Commented:
thanks
rrzCommented:
Thanks for the points.
I would have been glad to share points with bloodredsun.
Are you using Tomcat ?  Did you find your translated file in Tomcat's work directory ?  You will learn a lot by looking at it. Its name will similar to the name you gave your JSP.   Look for something like   yourName_jsp.java           rrz
bloodredsunCommented:
Thanks rrz but these points are all yours ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.