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

JSP中String的问题
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
  <%
    String   a=new   String( "administrator ");
String   b;
b=a.subString(3,3);
      out.print(a);
  out.print(b);
    %>
</body>
</html>
---------------------------------------------------
运行结果:
---------------
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   10   in   the   jsp   file:   /Untitled-1.jsp
Generated   servlet   error:
D:\Program   Files\Tomcat   5.0\work\Catalina\localhost\myjsp\org\apache\jsp\Untitled_002d1_jsp.java:56:   cannot   resolve   symbol
symbol     :   method   subString   (int,int)
location:   class   java.lang.String
b=a.subString(3,3);
      ^
1   error


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
----------------------------请高手指导一二---------------


------解决方案--------------------
b=a.subString(3,3);

S 应该小写吧

b = a.substring(3,3);
------解决方案--------------------
jsp页面默认会导入java.lang包~~~应该不用再舔加~~


b = a.substring(3,3);这里错误~~~截截取字符串的结束位置一定要大于起始位置,不然会报错误,你改成b = a.substring(3,4); 就可以了
------解决方案--------------------
不是这个意思,第一个3表示从第4个元素开始。第2个3表示结束在第3个元素。
所以楼主的方法即使编译成功也不会输出结果。

我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html