日期:2014-05-18  浏览次数:20874 次

jsp调用javabean出错
firstbean---src
  ---WebRoot
  --------fbean.jsp
  ---------WEB-INF
  ------classes
  -------firstjavabean.class
如果输入http://localhost:8080/firstbean/
可以看到index.jsp的内容
如输入http://localhost:8080/firstbean/fbean.jsp,然后运行出错
   

HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /fbean.jsp
firstjavabean cannot be resolved to a type
1: <%@ page contentType="text/html;charset=gb2312" %>
2: <jsp:useBean id="fb" scope="session" class="firstjavabean" />
3: <html>
4: <%
5: fb.setfirstproperty("my first");


An error occurred at line: 2 in the jsp file: /fbean.jsp
firstjavabean cannot be resolved to a type
1: <%@ page contentType="text/html;charset=gb2312" %>
2: <jsp:useBean id="fb" scope="session" class="firstjavabean" />
3: <html>
4: <%
5: fb.setfirstproperty("my first");


An error occurred at line: 2 in the jsp file: /fbean.jsp
firstjavabean cannot be resolved to a type
1: <%@ page contentType="text/html;charset=gb2312" %>
2: <jsp:useBean id="fb" scope="session" class="firstjavabean" />
3: <html>
4: <%
5: fb.setfirstproperty("my first");


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.


--------------------------------------------


------解决方案--------------------
<% 
fb.setfirstproperty("my first"); 
% > 
<%=fb.getfirstproperty()% > 
</html > 
改了也用JSP动作看看
------解决方案--------------------
我记的javabean一定要放在一个包里才可以的。 你试试把bean放到一个包里再在jsp页面里去调用试试。。。。
------解决方案--------------------
楼上的是正解。
一般javaBean是需要放到一个包里的。
------
解决的办法:
修改firstjavabean.java,添加在一个包中。
jsp页面调用其相应包名+firstjavabean
------解决方案--------------------
你的<%@ page contentType="text/html;