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 type not visible Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "type not visible" Watch "type not visible" New topic
Author

type not visible

Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 236
Hi there,

I'm having a problem trying to figure out why it is a JSP page cannot see a class named TableData. In a servlet I saved an instance of TableData into the Session object, like so:

HttpSession session = request.getSession(true);
TableData td = new TableData(...);
session.setAttribute("EnrollTableData", td);

Then I attempt to retrieve the TableData object in my JSP page like so:
<%@ page import="mvcs.*" %>
<%
....
TableData td = (TableData)session.getAttribute("EnrollTableData");
....
%>

The TableData class is in a directory named mvcs. It exists in two places actually. See the directory structure below. I did include the package statement "package mvcs;" in my TableData.java file.

When I try to access the JSP page I get the following message:
The type TableData is not visible

This doesn't make sense to me. TableData is in the same directory as a lot of the other classes I created, and I can access them, no problem.
My directory structure is as follows. Maybe this will help?

scholastic
|
|__admin
|     |__ConfirmEnrollment.jsp
|     |__mvcs
|          |__TableData.java
|          |__TableData.class
|
|__WEB-INF
     |__classes
          |__mvcs
               |__TableData.java
               |__TableData.class


Please advise,

Alan

[ September 26, 2005: Message edited by: Alan Shiers ]
[ September 26, 2005: Message edited by: Alan Shiers ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

At a glance your code looks fine.
I would double check that the TableData.java file under WEB-INF has the correct package statement and then delete the classfile & recompile.


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

Joined: Sep 24, 2003
Posts: 236
Hi,

I did check the package statement, and it's fine. I did recompile and it made no difference. Any other suggestions?

Alan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

If the servlet is executing and the problem only arises when the JSP has been forwarded to, then the class has been sucessfully loaded.

I can only speculate at this point that there's a subtle problem within your JSP.

Please post the relevant parts of you JSP verbatim. Please make sure the posted code is correct and please use the UBB code tags to preserve formatting.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 236
Hi there,

I was able to solve part of my problem. It turned out I hadn't declared the class TableData as "public". I did that and recompiled, however I'm getting a differenct error message now:

Cannot resolve TableData

The JSP page is below. I only reference the TableData class once, that is with the statement:

TableData td = (TableData)session.getAttribute("EnrollTableData");

Obviously, it does see the class TableData or it would be giving me a totally different error message, like: ClassNotFoundException. So why would it be saying it cannot resolve it?

Alan


Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 236
Aahh! I just figured it out. The problem lie on the line:

if(companyID == null || administratorID == null || TableData == null)

it was supposed to be:

if(companyID == null || administratorID == null || td == null)

I knew it had to be something really simple and dumb. I got it working now guys. Thanks for your help.

Alan
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I'll just add that it would be a good idea for you to try and remove scriptlets from your JSP's. Move all that code to a Servlet and then, if using JSP 2.0, use EL to get to the data. Otherwise you can use JSP tags. And then add JSTL in with that and you are cooking with fire.

I realize that if you are in the learning phases, this might be a lot to take on at once, but the sooner you commit to, the better off you'll be and it will also make it easier to debug your apps in the future since there is a better seperattion of concern (MVC).


GenRocket - A Test Data Generation Platform
 
Consider Paul's rocket mass heater.
 
subject: type not visible
 
Similar Threads
Validate() method of ActionForm
No scrolling in text input after uppercase ?
Value in dropdown from servlet
custom tag help
servlets/jsp