当前位置: 代码迷 >> Java Web开发 >> jsp中标签useBean中的class属性值如何设置
  详细解决方案

jsp中标签useBean中的class属性值如何设置

热度:245   发布时间:2016-04-17 00:20:47.0
jsp中标签useBean中的class属性值怎么设置
我用Myeclipse中写的beanTest.jsp,我的原文件的主要代码 

 <body>
  <jsp:useBean id="p1" class="lee.Person" scope="page">
  <jsp:setProperty name="p1" property="name" value="wawa"/>
  <jsp:setProperty name="p1" property="age" value="12"/>
  <jsp:getProperty name="p1" property="name"/>
  <jsp:getProperty name="p1" property="age"/>
  </jsp:useBean>
  </body>

Person.java放在WebRoot/WEB-INF/src/lee目录下代码如下

public class Person {
private int age;
private String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


在Tomcat6.0运行出现的错误如下

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:161)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:338)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:630)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:338)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.ClassNotFoundException: org.apache.jsp.beanTest_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:200)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:628)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:338)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

这个目录WebRoot/WEB-INF/src/lee是放编写的java文件吗? 还是放到WebRoot/WEB-INF/classes目录下?

------解决方案--------------------
在创建MyEclipse时不是有一个src包吗?里面是创建Java文件的啊?
  相关解决方案