jsp中javabean调用报错The value for the useBean class attribute javabean.hello is invalid
tomcat版本5.5.28UsreData.java代码publicclassUserData{privateStringName;privateStringNum;p...
tomcat版本5.5.28
UsreData.java代码
public class UserData
{
private String Name;
private String Num;
public UserData()
{
}
public void setUserName(String name)
{
Name=name;
}
public void setUserNum(String num)
{
Num=num;
}
public String getUserName()
{
return Name;
}
public String getUserNum()
{
return Num;
}
}
生成的UserData.class放在E:\tomcat\webapps\myapp\WEB-INF\classes
javabean.jsp代码为
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<title>JavaBean</title>
<body>
<jsp:useBean id="data" scope="page" class="javabean.UserData"/>
<jsp:setProperty name="data" property="userName" value="Tom"/>
<%
data.setUserNum("123");
%>
Your Name Is:<font color=bule>
<jsp:getProperty name="data" property="userName"/>
</font><br>
The Number Is:<font color=bule>
<jsp:getProperty name="data" property="userNum"/>
</font>
</body>
</html>
报错
org.apache.jasper.JasperException: /javabean.jsp(5,0) The value for the useBean class attribute javabean.UserData is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1191)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1117)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2222)
org.apache.jasper.compiler.Node$Root.accept(Node.java:457)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
org.apache.jasper.compiler.Generator.generate(Generator.java:3326)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:220)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
小弟刚学,请大侠帮忙
我根据你的答案做了修改
UserData.java
public class UserData
{
private String name;
private String number;
public UserData()
{
}
public void setName(String newName)
{
name=newName;
}
public void setNumber(String newNumber)
{
number=newNumber;
}
public String getName()
{
return name;
}
public String getNumber()
{
return number;
}
}
报错
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 5 in the jsp file: /javabean.jsp
UserData cannot be resolved to a type 展开
UsreData.java代码
public class UserData
{
private String Name;
private String Num;
public UserData()
{
}
public void setUserName(String name)
{
Name=name;
}
public void setUserNum(String num)
{
Num=num;
}
public String getUserName()
{
return Name;
}
public String getUserNum()
{
return Num;
}
}
生成的UserData.class放在E:\tomcat\webapps\myapp\WEB-INF\classes
javabean.jsp代码为
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<title>JavaBean</title>
<body>
<jsp:useBean id="data" scope="page" class="javabean.UserData"/>
<jsp:setProperty name="data" property="userName" value="Tom"/>
<%
data.setUserNum("123");
%>
Your Name Is:<font color=bule>
<jsp:getProperty name="data" property="userName"/>
</font><br>
The Number Is:<font color=bule>
<jsp:getProperty name="data" property="userNum"/>
</font>
</body>
</html>
报错
org.apache.jasper.JasperException: /javabean.jsp(5,0) The value for the useBean class attribute javabean.UserData is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1191)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1117)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2222)
org.apache.jasper.compiler.Node$Root.accept(Node.java:457)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
org.apache.jasper.compiler.Generator.generate(Generator.java:3326)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:220)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
小弟刚学,请大侠帮忙
我根据你的答案做了修改
UserData.java
public class UserData
{
private String name;
private String number;
public UserData()
{
}
public void setName(String newName)
{
name=newName;
}
public void setNumber(String newNumber)
{
number=newNumber;
}
public String getName()
{
return name;
}
public String getNumber()
{
return number;
}
}
报错
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 5 in the jsp file: /javabean.jsp
UserData cannot be resolved to a type 展开
展开全部
1.你类中的两个属性是 Name,Num
应该小写开头 如:name,num
2.set get 方法也不对 因该是setName(),getName(),setNum(),getNum()
3.<jsp:getProperty name="data" property="userName"/>,
<jsp:setProperty name="data" property="userName" value="Tom"/>
这里的property的属性名跟类中的属性名一直 如:property="name"
4.<jsp:useBean id="data" scope="page" class="javabean.UserData"/>
这里的class是你写的类的包结构(包路径)。类
你再试一试! 还有问题再找我..........
应该小写开头 如:name,num
2.set get 方法也不对 因该是setName(),getName(),setNum(),getNum()
3.<jsp:getProperty name="data" property="userName"/>,
<jsp:setProperty name="data" property="userName" value="Tom"/>
这里的property的属性名跟类中的属性名一直 如:property="name"
4.<jsp:useBean id="data" scope="page" class="javabean.UserData"/>
这里的class是你写的类的包结构(包路径)。类
你再试一试! 还有问题再找我..........
展开全部
classes 文件夹下加个包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.你类中的两个属性是
Name,Num
应该小写开头
如:name,num
2.set
get
方法也不对
因该是setName(),getName(),setNum(),getNum()
3.<jsp:getProperty
name="data"
property="userName"/>,
<jsp:setProperty
name="data"
property="userName"
value="Tom"/>
这里的property的属性名跟类中的属性名一直
如:property="name"
4.<jsp:useBean
id="data"
scope="page"
class="javabean.UserData"/>
这里的class是你写的类的包结构(包路径)。类
你再试一试!
还有问题再找我..........
Name,Num
应该小写开头
如:name,num
2.set
get
方法也不对
因该是setName(),getName(),setNum(),getNum()
3.<jsp:getProperty
name="data"
property="userName"/>,
<jsp:setProperty
name="data"
property="userName"
value="Tom"/>
这里的property的属性名跟类中的属性名一直
如:property="name"
4.<jsp:useBean
id="data"
scope="page"
class="javabean.UserData"/>
这里的class是你写的类的包结构(包路径)。类
你再试一试!
还有问题再找我..........
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询