You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Novotny <JD...@lbl.gov> on 2001/04/26 20:43:45 UTC

jsp function declaration

Hi,

    I have  a very simple JSP function that looks like:

<%! public String isSelected(String var, String checkvar) {
             if (var.equals(checkvar)) {
                 return "selected";
             } else
                 return "";
             }
        }
%>

    Only problem is whenever I load my page, I get the following error:

org.apache.jasper.JasperException: Unable to compile
/usr/local/tomcat/tomcat-3.3-m2/work/DEFAULT/demo/jsp/filetransfer/showfiles_1.java:25:
Class or interface declaration expected.
    static {
    ^
/usr/local/tomcat/tomcat-3.3-m2/work/DEFAULT/demo/jsp/filetransfer/showfiles_1.java:13:
class jsp.filetransfer.showfiles_1 must be declared abstract. It does
not define void _jspService(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) from class
org.apache.jasper.runtime.HttpJspBase.
public class showfiles_1 extends org.apache.jasper.runtime.HttpJspBase {

             ^
2 errors


    I've tried adding thsi snippet to the numguess.jsp example without
any problem and all the books I've read indicate this is perfectly
acceptable programming.

    Any ideas, why adding methods doesn't work with my page?

    Thanks very much, Jason


--
Jason Novotny               novotny@george.lbl.gov
Home: (510) 610-8360        Work: (510) 486-8662
NERSC Distributed Computing http://www-didc.lbl.gov




Re: jsp function declaration

Posted by Scott Tatum <sc...@wcom.com>.
If that is the correct code for the method, then the problem is you have a closing brace
for the else without an open brace. What's probably happening is the brace you think is
closing the else is actually closing the method, and the brace you think is closing the
method is closing the entire class before the service method is auto generated during
conversion to a servlet, thus the error. Either add an opening brace for the else, or
remove one of the closing braces at the end.

-Scott

Jason Novotny wrote:

> Hi,
>
>     I have  a very simple JSP function that looks like:
>
> <%! public String isSelected(String var, String checkvar) {
>              if (var.equals(checkvar)) {
>                  return "selected";
>              } else
>                  return "";
>              }
>         }
> %>
>
>     Only problem is whenever I load my page, I get the following error:
>
> org.apache.jasper.JasperException: Unable to compile
> /usr/local/tomcat/tomcat-3.3-m2/work/DEFAULT/demo/jsp/filetransfer/showfiles_1.java:25:
> Class or interface declaration expected.
>     static {
>     ^
> /usr/local/tomcat/tomcat-3.3-m2/work/DEFAULT/demo/jsp/filetransfer/showfiles_1.java:13:
> class jsp.filetransfer.showfiles_1 must be declared abstract. It does
> not define void _jspService(javax.servlet.http.HttpServletRequest,
> javax.servlet.http.HttpServletResponse) from class
> org.apache.jasper.runtime.HttpJspBase.
> public class showfiles_1 extends org.apache.jasper.runtime.HttpJspBase {
>
>              ^
> 2 errors
>
>     I've tried adding thsi snippet to the numguess.jsp example without
> any problem and all the books I've read indicate this is perfectly
> acceptable programming.
>
>     Any ideas, why adding methods doesn't work with my page?
>
>     Thanks very much, Jason
>
> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 610-8360        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov

--
Scott Tatum | scott.tatum@wcom.com
Senior Applications Developer, Special Projects
WorldCom | http://www.wcom.com/