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 Error in  jsp on instanciating a java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Error in  jsp on instanciating a java class" Watch "Error in  jsp on instanciating a java class" New topic
Author

Error in jsp on instanciating a java class

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hello,
This is the first time I'm attempting to instantiate a java class inside of a jsp page. My java class compiles without errors. At the top of the class I do have a package statement and I do import the class implicitly into the jsp page, but when I try to do

MyClass myclass = new MyClass();

inside of my jsp page, I get an error "MyClass cannot be resolved to a type". I have no idea what's wrong, but it sounds like could be something very basic. Could anybody please give me some pointers for this error?
Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Please post the relevant code from the JSP. (Be sure to use UBB code tags to preserve the formatting).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
alban maillere
Greenhorn

Joined: Nov 06, 2006
Posts: 6
how do you "implicitly" import a class in your jsp?
without an import tag for the specific class, it won't work


while(true){<br /> this.put(BeerFactory.newInstance());<br />}
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I decided to create a java bean and attempt to import the EpisDBUtil class into the bean instead of a jsp file. Both, the bean and the EpisDBUtil (java and class files) are in the same folder "beans". Both java files contain the same package statement. When I compile the EpisSelectBean, I get the same error I was getting earlier:"EpisSelectBean cannot be resolved to a type". Please Help!
Here is how my EpisSelectBean bean:

Here is how my EpisSelectBean bean:

package jsps.beans;

import jsps.*;
import java.util.*;
public class EpisSelectBean implements java.io.Serializable{
private EpisDBUtil episdb;

public EpisSelectBean(){}

}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

lilya,

I asked you to do two thing, neither of which you did.

First, please show us the relevant JSP code. The bean code is rather less helpful.

Secondly, when posting code on the Ranch, please use the UBB code tags to preserve formatting. It is incredibly hard to read unformatted code and many people will not bother. Please read this. You have been posting on the Ranch long enough to learn how to use it effectively.
[ November 06, 2006: Message edited by: Bear Bibeault ]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I'm not sure what UBB tags are,
but the jsp code is very basic:

<%@ page import="java.io.*, java.util.*, myjsps.*" %>
<%
EpisDBUtil episdb = new EpisDBUtil();
%>

I store my files in webapps/myjsps. I was able to fix the errors in jsp file (what's above works fine), but but still get same errors in java files.
I think the errors have to do with configuration files...
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
On UBB code, its simple enough. When you are editing a message you will see a bunch of buttons underneath the editor in a section labelled "Instant UBB Code" One of those buttons is "CODE"
Simply select the text in the textarea, and push the "CODE" button. (Works on IE, don't know about firefox)
Or you can just manually write [ CODE] and [ /CODE] around the bits you want to do as "code" (remove the space to so that it renders correctly)

It should end up looking something like this:



Note also I added an import statement for the package where your bean was.
Also your beans should be deployed under the WEB-INF/classes directory

ie the class EpisSelectBean should be compiled to the file
[webappname]/WEB-INF/classes/jsps/beans/EpisSelectBean.class

Cheers,
evnafets
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Originally posted by liliya woland:
I'm not sure what UBB tags are,


I provided a link in my reply that has a detailed explanation. Do you even bother to read what people write?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
I provided a link in my reply that has a detailed explanation. Do you even bother to read what people write?

It seems that I don't, and just waste more of my time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in jsp on instanciating a java class