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

请教个JSP定义函数的问题
<%
final int count=10;
String[] msg=new String[count+1];
msg[count]="cssz";
String ch_str="一二三四五六七八九十";
for(int i=0;i<msg.length;i++)
  msg[i]="b"+(i+1);

String getStr(String en)
{
  String getstr;
  for(int j=0;j<msg.length;j++)
  {
if(en.equals(msg[j]))
  { 
  getstr=ch_str.charAt(j);
  }
  }
  return getstr;
}
%>

这个页面我是准备用 <%@ include file="" %>包含到另一个页面的
在这个页面定义的函数getStr
编译的时候总是报错 说 ';'expected 
出错的波浪线总是打在getStr(这个括号上 请教是怎么回事啊

------解决方案--------------------
把getStr()函数定义到:
<%! 
... 
%>


------解决方案--------------------

<%!

% > 
把变量定义括起来成为全局变量