943,952 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2186
  • JSP RSS
Feb 16th, 2008
0

Java bean problems! Argh

Expand Post »
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
java Syntax (Toggle Plain Text)
  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)
java Syntax (Toggle Plain Text)
  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!
Reputation Points: 10
Solved Threads: 0
Light Poster
eddy556 is offline Offline
32 posts
since Jan 2008
Feb 17th, 2008
0

Re: Java bean problems! Argh

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Feb 17th, 2008
0

Re: Java bean problems! Argh

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 :-)
Reputation Points: 10
Solved Threads: 0
Light Poster
eddy556 is offline Offline
32 posts
since Jan 2008
Feb 17th, 2008
0

Re: Java bean problems! Argh

> <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" /> ?
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: How to create a "web.xml" file for website?
Next Thread in JSP Forum Timeline: Any Sample Projects in JSP??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC