File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "useBean" Watch "useBean" New topic
Author

useBean

Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
While executing my jsp page which uses a Javabean, it throws an error as follows
* I am using j2ee1.4


* There is no problem while deploying. The class file is automatically getting added into web-inf/classes. But it is true that the beanclass file is not present in the automatically generated jsp classfile

The error is a s follows
------------------------
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-apps\MyJspear\war-ic_war\org\apache\jsp\Register_jsp.java:43: cannot resolve symbol
[javac] symbol : class MyClass
[javac] location: class org.apache.jsp.Register_jsp
[javac] MyClass objusr = null;
[javac] ^


Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-apps\MyJspear\war-ic_war\org\apache\jsp\Register_jsp.java:45: cannot resolve symbol
[javac] symbol : class MyClass
[javac] location: class org.apache.jsp.Register_jsp
[javac] objusr = (MyClass) _jspx_page_context.getAttribute("objusr", PageContext.SESSION_SCOPE);
[javac] ^


Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-apps\MyJspear\war-ic_war\org\apache\jsp\Register_jsp.java:48: cannot resolve symbol
[javac] symbol : class MyClass
[javac] location: class org.apache.jsp.Register_jsp
[javac] objusr = (MyClass) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "MyClass");
[javac] ^


Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-apps\MyJspear\war-ic_war\org\apache\jsp\Register_jsp.java:85: cannot resolve symbol
[javac] symbol : variable objuser
[javac] location: class org.apache.jsp.Register_jsp
[javac] boolean reg=objuser.insertUserDetails();
[javac] ^
[javac] 4 errors




org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:88)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:337)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:429)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:489)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:456)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:516)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:307)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:251)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)


note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.


--------------------------------------------------------------------------------

Sun-Java-System/Application-Server

What might be the problem?
Please help me.

Rgds
SRee


Sree
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

Did you import MyClass?

Is MyClass in a package other than the default?

Have you read the JSP FAQ entry on this very subject?
[ December 08, 2005: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
HI

MyClass is in the default package


Rgds
Sree
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sree kanth:
HI

MyClass is in the default package


Rgds
Sree


Starting with Java 1.4.1 non packaged (default package) classes can not be imported from packaged classes.
Put your classes in packages.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
Thank u so much BEN.
Now it is working.
But why such a restriction is required?


Rgds
Sree
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The restriction was always in the JRE spec but older versions of Sun's JRE let it slip through the cracks.
They tightened up the implementation in 1.4.1.

I'm not sure what the exact reason was but I think it's always been a good idea to explicitly package your classes.




[Added:]
See section 8, Bullet 2 in this page.
They don't really go into the reasoning here either.
http://java.sun.com/j2se/1.4/compatibility.html#incompatibilities1.4

I'll add this link to the JSP FAQ as well.
[ December 12, 2005: Message edited by: Ben Souther ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: useBean
 
Similar Threads
problem in importing package in jsp
Prb in compiling the JSP
Setting page var in scriptlets function?
Problem with datetime fields
Multiple forms in a single JSP page