gpt4 book ai didi

java - 编译器错误: cannot find symbol,符号: class JSPWriter,位置:类转换器

转载 作者:行者123 更新时间:2023-12-01 10:39:01 26 4
gpt4 key购买 nike

我是 Java 新手,只是想编译一个类。

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.*;


public class Converter extends BodyTagSupport{

private String _to;

public String getTo() {
return _to;
}

public void setTo(String to) {
_to = to;
}


public int doAfterBody(){

try {
BodyContent bc = getBodyContent();
JSPWriter out = bc.getEnclosingWriter();
double result = 0.0;
if(_to.equals("F")) {
result = toFahrenheit(Double.parseDouble(bc.getString()));
} else {
result = toKelvin(Double.parseDouble(bc.getString()));
}
out.write("Resultado: " + result);

} catch(Exception E) {

}

return EVAL_PAGE; //tells servlet container to process rest of JSP page.
}

private double toFahrenheit(double c){
return 32.0 + (c*1.8);
}

private double toKelvin(double c){
return 273.0 + c;
}

编译器错误为

cannot find symbol, symbol: class JSPWriter, location:class Converter

我不明白为什么会出现此错误,所以请帮助我。

我已经将 servlet-api.jar 和 jsp-api.jar 添加到 CLASSPATH 中。

最佳答案

Java 区分大小写。改变

JSPWriter out = bc.getEnclosingWriter();

JspWriter out = bc.getEnclosingWriter();

关于java - 编译器错误: cannot find symbol,符号: class JSPWriter,位置:类转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34518582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com