Hello ! I've been trying to create and use a simple bean in jsp page I put it under \webapps\try\WEB-INF\classes\beanspackage where beanspackage is the package of this bean. Everything works fine but when I'm trying to put it under \webapps\try\WEB-INF\classes\ and comment the package diclaration inside the bean i get error that it's impossible to create the object of the bean. Is it a necessary point to put beans into packages ? Thanks !
Joined: Aug 27, 2003
It is not necessary to have it in package.It works fine even if it is not in package. Are you using jsp:usebean ? Please paste the jsp code and the error...so that we can have a look at it
Joined: Sep 12, 2001
Hi, Thats the problem with the Tomcat engine...the one that converts the JSP file into a Java Servlet. If you open the servlet, it will have a syntax error. If you have a page import with "MyClass".. It wil try to generate a Java Servlet code with.. import MyClass; Which is wrong by java syntax...we are not suppose to import a java class which is in the same package. So, you might try to remove the page import from jsp file, even then Tomact will nto do the job. I am not sure, one of my friend did something and fixed this issue. I am not aware of it. Anyhow, It is adivisable to place the file in a package.
Shankar Shanmugam<br />Sun Certified Programmer for Java 2 Platform<br />Sun Certified Developer for Java 2 Platform<br />Email: email@example.com<br /> "Walking on water and building IT Architecture from <br /> specification are easy if and only if both are frozen"<br />-----------------------------------------------
Joined: Jun 21, 2003
It works fine %CATALINA_HOME%\webapps\try\index.jsp
[ September 03, 2003: Message edited by: Kaspar Minosiants ]
Joined: Jun 06, 2002
Your bean MUST be in a package. Period. This has to be the most commonly asked question around here. It's the first question I ever asked. Java 1.4 does not allow a packaged class to import or otherwise access a packageless class. When Tomcat translates your JSP into a Java class file, it puts the class into a package.
I don't think so, you don't need to pack your beans to use 'em in your JSP. I got an web-app that works without packages: FooJSP.jsp: <%@ page language="java" import="FooBean" %> <jsp:useBean id="anything" scope="request" type="FooBean"/> The source of FooBean is in my classpath root (/WEB-INF/classes). And it works fine.
Author and all-around good cowpoke
Joined: Mar 22, 2000
Every class used in a JSP or servlet should be in a package. You may get one particular configuration of server to work without it but you are just asking for trouble down the road with mysterious errors. Bill.
Tomcat translates your JSP into a servlet class in the package "org.apache.jsp". Other containers probably do something similar. Since your servlet is in a package, its code cannot access any packageless class. This is a change to Java, as of 1.4.