Java bean problems! Argh

Reply

Join Date: Jan 2008
Posts: 32
Reputation: eddy556 is an unknown quantity at this point 
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

Java bean problems! Argh

 
0
  #1
Feb 16th, 2008
Okay, here we go. I am trying to learn how to use javabeans properly and so I've created a small bean which just writes text to the screen. I keep getting the error:

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

An error occurred at line: 6 in the generated java file
Only a type can be imported. mybeans.processFormBean resolves to a package

and can't figure out what to do. Here is my code:

nob.jsp
  1.  
  2. <%@ page import="mybeans.processFormBean" %>
  3.  
  4. <jsp:useBean id="example" class="beans.example" />
  5.  
  6.  
  7.  
  8. <form name="example" action="nob.jsp" method="get">
  9. <input type="text" name="value">
  10.  
  11. <input type="submit" value="submit">
  12. </form>
  13.  
  14. <jsp:getProperty name="value" property="value" />
  15.  
  16. <%= example.getValue() %>

example.java (but I have obviously compiled it)
  1. package beans;
  2.  
  3. import java.sql.*;
  4.  
  5. public class example
  6. {
  7. private String value = "cheese";
  8.  
  9. public void setValue(String value) { this.value = value; }
  10.  
  11. public String getValue() { return value; }
  12.  
  13.  
  14. public void test()
  15. {
  16. System.out.println("The bean worked");
  17. }
  18.  
  19. }

I have checked the package names and the folders they are in etc, here is my classpath: .;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip

Thanks for your help!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,648
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 473
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Java bean problems! Argh

 
0
  #2
Feb 17th, 2008
Your problem seems to be this line in your JSP file:
> <%@ page import="mybeans.processFormBean" %>
What exactly is processFormBean here? Is it a package? Are you trying to import all the classes from the processBean package? If yes, then you are doing it the wrong way. To import all the classes of a particular package, you need to do something like:

<%@page import="mybeans.processFormBean.*" %>
As a rule of thumb, *never* keep anything in your JDK/JRE installation directory. Create a separate lib folder for your application which will contain all the libraries specifically used by your applications. In case of a web application, this would be the lib directory inside WEB-INF. Also, the lib directory implicitly forms a part of your classpath so you don't have to explicitly set it anywhere.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 32
Reputation: eddy556 is an unknown quantity at this point 
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

Re: Java bean problems! Argh

 
0
  #3
Feb 17th, 2008
OKay thanks, now I'm getting the error:

org.apache.jasper.JasperException: Attempted a bean operation on a null object.
org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:603)
org.apache.jsp.nob_jsp._jspService(nob_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
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)

Thanks for your help :-)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,648
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 473
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Java bean problems! Argh

 
0
  #4
Feb 17th, 2008
> <jsp:getProperty name="value" property="value" />
This means "get the 'value' property of a bean identified by the name 'value'", but there is no such bean in your case which goes by the name of 'value'. Maybe you wanted to do something like <jsp:getProperty name="example" property="value" /> ?
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JSP Forum
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC