I'm new with Java and just trying to compile a class.
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;
}
The compiler error is
cannot find symbol, symbol: class JSPWriter, location:class Converter
I don't undertand why I get this error, so please help me out.
I've already added the servlet-api.jar and jsp-api.jar to the CLASSPATH.
Java is case sensitive. Change
JSPWriter out = bc.getEnclosingWriter();
to
JspWriter out = bc.getEnclosingWriter();