当我尝试使用Struts运行用Java编写的Web应用程序类时出现以下错误:
Class" Converter"既没有主方法,也没有servlet 在web.xml中指定Class" chap4.Converter"没有主要的 方法
这是项目中唯一的类(类名为Converter.java):
package chap4;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class Converter extends BodyTagSupport{
private String _to = "F"; // This will correspond to the to attribute of your custom tag. By def, the conversion is to Fahrenheit.
public String getTo()
{
return _to;
}
public void setTo(String _to1)
{
_to = _to1;
}
public int doAfterBody()
{
try
{
...
}
catch(Exception ignore){}
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;
}
}
我还在一个名为lab4-converter.TDL
的文件中添加了这个<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>0.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>message</shortname>
<tag>
<name>
write
</name>
<tagclass>
chap4.Converter
</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>_to</name>
<required>false</required>
</attribute>
</tag>
</taglib>
然后我在web.xml中添加了这个:
<taglib>
<taglib-uri>/tags/lab4-converter</taglib-uri>
<taglib-location>/WEB-INF/lab4-converter.tld</taglib-location>
</taglib>
我错过了什么或做错了什么?感谢。