在尝试处理 jsp 上的字符串时,我在代码中使用了 string.repalace() 方法,但我不断收到以下错误:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 9 in the jsp file: /final2.jsp
Cannot invoke replace(String, String) on the array type String[]
6: public void main (String str) {
7: String [] text = StringUtils.substringsBetween(str,"#","#");
8: for (int i=0; i<text.length;i++) {
9: String newtext = text.replace("#"+text[i]+"#","<b>"+text[i]+"</b>");
10: }
11: //blank line
12: }
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java: 102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
我的代码如下:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@page import="org.apache.commons.lang.StringUtils" %>
<%
final class setext {
public void main (String str) {
String [] text = StringUtils.substringsBetween(str,"#","#");
for (int i=0; i<text.length;i++) {
String newtext = text.replace("#"+text[i]+"#","<b>"+text[i]+"</b>");
}
}
}
%>