• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 937
  • Last Modified:

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




0
royalcyber
Asked:
royalcyber
  • 3
  • 3
  • 2
1 Solution
 
rrzCommented:
Try it this way.

<%!
public string convert_null(string value){
   if (value==null || value.length()==0 || "null".equals(value)){
      return "";
   } else {
      return value;
   }
}
%>
0
 
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.
0
 
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
0
 
bloodredsunCommented:
Either in a javabean or in another java class that you invoke in a scriptlet..
0
 
royalcyberAuthor Commented:
thanks
0
 
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
0
 
bloodredsunCommented:
Thanks rrz but these points are all yours ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now