Vishwa wrote:
>
> Hi Rathinavel,
>
>   The class is not in any package as such. I have copied the class file
> on to the public_html folder. Should I put the DataManager class in a
> package and import it ?.
>
> Thanks
> vishwa

It's recommended that you place your beans in a package, to avoid this type
of problems as well as to get your code organized. What you see here is a
problem
(bug?) with Java not being able to recognize classes in the "unnamed package"
when
used in a class that's in a named package. The servlet generated from the JSP
page
is placed in a named package (pagecompile.jsp in this case, it varies between
implementations), and therefore it incorrectly believes that your bean in the
"unnamed package" is in the same package.

Two solutions:
1) Add <%@ page import="DataManager" %>
2) Better, place the DataManager in a package and add an import and use the
   short name, or just use the fully qualified name for the DataManager in the
   scripting elements.

Another problem with this page, assuming you want init() to be called when
the page is first used, is that the method you need to define is actually
called jspInit() (see the JSP spec for details). You may also want to use
a servlet for all kinds of real request processing and just forward to a JSP
page for presentation. This way you can avoid putting so much code in your
JSP pages (see the archives of this list for discussions about MVC and Model 2).

Hans

> Rathinavel P wrote:
> >
> > Sorry! just the basic question, have you imported the DataManager class ??
> >
> > with regards,
> >          rathna.
> >
> > Vishwa wrote:
> >
> > > Hello all,
> > >
> > > I am new to JSP, but have been working with servlets. I am trying to
> > > instantiate an object in my jsp page. But I get a page compilation
> > > error,
> > >
> > > code:
> > >
> > > <%@page info="General query jsp"%>
> > > <html>
> > > <body>
> > > <%!     private DataManager dbManager;
> > >         public void init() {
> > >                 dbManager = new DataManager("newTTSource",null,null);
> > >         }
> > > %>
> > > <%=request.getParameter("query")%>
> > > <form name='testForm' action='/query.jsp' method='get'>
> > > <input type=text name='query' size=50></input>
> > > <input type=submit>
> > > </form>
> > > </body>
> > > </html>
> > >
> > > error:
> > >
> > > Error during compilation :
> > >
> > > C:\JavaWebServer2.0\tmpdir\default\pagecompile\jsp\_query.java:25: Class
> > > pagecompile.jsp.DataManager not found in type declaration.
> > >                 private DataManager dbManager;
> > >                                              ^
> > > C:\JavaWebServer2.0\tmpdir\default\pagecompile\jsp\_query.java:27: Class
> > > pagecompile.jsp.DataManager not found in type declaration.
> > >                         dbManager = new
> > > DataManager("newTTSource",null,null);
> > >                                         ^
> > > 2 errors

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to