index.jsp代码如下:
<%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML> <html> <jsp:useBean id="test1" class="Test1" scope="page"/> <jsp:setProperty name="test1" property="a" value="12" property="b" value="0.1"/> <jsp:getProperty name="test1" property="a"/> </html>
Test1.java代码如下:
public class Test1{
private int a;
private int b;
public int getA(){
return a;
}
public void setA( int a){
this.a=a;
}
public int getB(){
return b;
}
public void setB(int b){
this.b=b;
}
}
把这两个文件部署到MyEclipse的Web项目中能正确输出结果:12。现在让它脱离IDE,在Tomcat的Web目录中新建文件夹test,把这两个文件放在里面,用javac编译test1.java生成test1.class也放到test里, 启动Tomcat7访问index.jsp却提示Attribute qualified names must be unique within an element错误;用Tomcat6提示The value for the useBean class attribute Test1 is invalid.,是不是Tomcat的配置有问题,求帮忙!
The value for the useBean class attribute Java is invalid
这句说的很清楚,类属性“java”无效,因为java是关键字!
把类名Java和属性名java改下试试,这个属于特殊名词。