|
-
Dec 11th, 2001, 06:36 PM
#1
Thread Starter
Addicted Member
JSP trouble
What I'm trying to do: I want to define an object in my jsp script and, perhaps later, run some methods on it. For now I'm keeping it as simple as possible. When I compile the following class, incorporate it into the package and call it from the jsp, I get the errors shown below.
Here's my super short JSP script:
<%@ page import="my.package.*" %>
<%! Wheedle a = new Wheedle(request, session); %>
Here's my Java Class that I'm calling from my script (The ['s aren't really there):
[ package my.package;
[ import javax.servlet.http.*;
[ class Wheedle {
[ public Wheedle(HttpServletRequest r, HttpSession s) {
[ System.out.println("Hi Earth");
[ }
[ }
Here are the JSP error messages that I receive on the browser:
[org.apache.jasper.JasperException: JASPER: Unable to compile class for JSPC:\WINNT\TEMP\JettyContext21934.tmp\_0002fexport_0002fwhy_0002ejspwhy_jsp_0.java:21: Can't access class my.package.Wheedle. Class or interface must be public, in same package, or an accessible member class.
[ Wheedle a = new Wheedle(request, session);
[ ^
[C:\WINNT\TEMP\JettyContext21934.tmp\_0002fexport_0002fwhy_0002ejspwhy_jsp_0.java:21: Can't access class my.package.Wheedle. Class or interface must be public, in same package, or an accessible member class.
[ Wheedle a = new Wheedle(request, session);
[ ^
[C:\WINNT\TEMP\JettyContext21934.tmp\_0002fexport_0002fwhy_0002ejspwhy_jsp_0.java:21: Undefined variable: request
[ Wheedle a = new Wheedle(request, session);
[ ^
[C:\WINNT\TEMP\JettyContext21934.tmp\_0002fexport_0002fwhy_0002ejspwhy_jsp_0.java:21: Undefined variable: session
[ Wheedle a = new Wheedle(request, session);
[ ^
[4 errors
Any ideas why this isn't working?
-
Dec 12th, 2001, 06:56 AM
#2
Member
For the first two try changing the class declaration to public class Wheedle and make sure you're really compiling it (stupid mistakes are the most common).
-
Dec 12th, 2001, 02:38 PM
#3
Thread Starter
Addicted Member
Thanks filburt1, that helped. I figured out the other problem as well. I removed the '!' from the declaration in the jsp and that solved the problem of the other two error messages. I guess that items defined in the <%! areas don't know anything about the session and request objects, whereas if the declaration is declared as a scriptlet, i.e. the <% tag, you can declare object a that is global AND you get access to request and session.
cudabean
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|