0

我是 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;
    }

编译器错误是

找不到符号,符号:类 JSPWriter,位置:类转换器

我不明白为什么我会收到这个错误,所以请帮帮我。

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

4

1 回答 1

1

Java 区分大小写。改变

JSPWriter out = bc.getEnclosingWriter();

JspWriter out = bc.getEnclosingWriter();
于 2015-12-30T11:14:04.293 回答