日期:2014-05-18  浏览次数:20680 次

返回值的问题````````
返回值的问题````````
public   int   symbol(String   bit)      
                    {      
        int   result=0;
        String   anotherString=null;
        int   bitlength=0;
        String   S   =bit;
        boolean   b   =   Pattern.matches( "[a-zA-Z0-9]* ",S);
        try{anotherString   =   new   String(S.getBytes( "GBK "),   "ISO8859_1 ");}catch(Exception   e){}
        bitlength=(int)anotherString.length();  
        return     bitlength;
    }
报这个错误

org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   106   in   the   jsp   file:   /register/success.jsp
Generated   servlet   error:
Type   mismatch:   cannot   convert   from   int   to   String


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

怎么把bitlength的值返回出来````

------解决方案--------------------
bitlength=(int)anotherString.length();
return bitlength;
这个应该没问题吧,手头没环境,我觉得也没必要cast
------解决方案--------------------
An error occurred at line: 106 in the jsp file: /register/success.jsp
Generated servlet error:
Type mismatch: cannot convert from int to String
-----------------------


不能把int转换成String,自己找找
------解决方案--------------------
运行了下没报错
------解决方案--------------------
STRING类型的.length()本身就是返回一个INT类型.没有必要在加上(INT)吧.
如果是TRY块中anotherString出现赋值错误的话.不知道下边进行求长度会出错还是。
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html