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

jsp中split的使用问题!!!谢谢!!
没有用过split函数,这是第一次用,出现如下问题,请指教是怎么回事呢?
谢谢!!!
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   7   in   the   jsp   file:   /cyhtgl0520/htmod.jsp

Generated   servlet   error:
        [javac]   Compiling   1   source   file

C:\Tomcat   5.0\work\Catalina\localhost\_\org\apache\jsp\cyhtgl0520\htmod_jsp.java:116:   cannot   find   symbol
symbol     :   method   Split(java.lang.String,java.lang.String)
location:   class   org.apache.jsp.cyhtgl0520.htmod_jsp
myArr=Split(PayDate, "| ");


------解决方案--------------------
1、如果用“.”作为分隔的话,必须是如下写法:String.split( "\\. "),这样才能正确的分隔开,不能用String.split( ". ");
2、如果用“|”作为分隔的话,必须是如下写法:String.split( "\\| "),这样才能正确的分隔开,不能用String.split( "| ");
“.”和“|”都是转义字符,必须得加 "\\ ";
3、如果在一个字符串中有多个分隔符,可以用“|”作为连字符,比如:“acount=? and uu =? or n=?”,把三个都分隔出来,可以用String.split( "and|or ");
------解决方案--------------------
拆分成String一维数组后循环输出即可。


<%@ page import= "java.sql.*,java.text.*,java.lang.String "%>
<%@include file= "conn.jsp "%>
<%
String Hmod = new String(request.getParameter( "HNo ").getBytes(
"ISO-8859-1 "));
String PayDate = " ";
String sql = "select * from InfoHt where HNo= ' " + Hmod + " ' ";
ResultSet rs = sts.executeQuery(sql);
try {
while (rs.next()) {
PayDate = rs.getString( "PayDate ").trim();
}
String[] myArr = PayDate.split( "\\| ");

for(int i=0;i <myArr.length;i++)
{
out.println(myArr[i]);
}

rs.close();
sts.close();
} catch (Exception e) {
out.println(e.getMessage());
}
%>

------解决方案--------------------
代码没有问题啊。。。
比如下面的测试:
public static void main(String[] args)
{
String PayDate = "20070501|20070601|20070701 ";
String[] myArr = PayDate.split( "\\| ");

for (int i = 0; i < myArr.length; i++)
{
System.out.println(myArr[i]);
}
}

输出:
20070501
20070601
20070701

------解决方案--------------------
lz能确定:PayDate = rs.getString( "PayDate ").trim(); 能得到值吗?
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html