Results 1 to 3 of 3

Thread: JSP trouble

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240

    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?

  2. #2
    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).

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    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
  •  



Click Here to Expand Forum to Full Width