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

<%@ page import="mybeans.processFormBean" %>

<jsp:useBean id="example" class="beans.example" />



<form name="example" action="nob.jsp" method="get">
<input type="text" name="value">

<input type="submit" value="submit">
</form>

<jsp:getProperty name="value" property="value" />

<%= example.getValue() %>

example.java (but I have obviously compiled it)

package beans;

import java.sql.*;

public class example
{
	private String value = "cheese";

	public void setValue(String value) { this.value = value; }

	public String getValue() { return value; }


	public void test()
	{
		System.out.println("The bean worked");
	}

}

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!

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.

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 :-)

> <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" /> ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.