Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

accessing .class file from jsp  RSS feed

 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have my jsp under the context root and the servlets and java files under
the WEB-INF directory.
I am unable to access the class file (CDclass)
Where should I save the java class files that are to be used by jsp?
--------- error
cart.jsp:11:1: No type with this name could be found at this location.
CDclass cdObj = (CDclass)cartItem.elementAt(0);
--------- code
<%
Vector cartItem = (CDclass)session.getValue("book");
(CDclass)cdObj = cartItem.elementAt(0);
:
%>
---------
Where should I place other java healper classes.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TOMCAT_HOME/webapps/YOUR_APP_NAME/WEB-INF/classes/YOUR_PACKAGE/YOUR_CLASS
 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I had not kept my java files in a package. I am able to access
it now.
Its is necessary to have all the servlets and other java classes
in a package ? Also do we need to add anything in the web.xml files for
the helper java classes and the javabeans ?

Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its is necessary to have all the servlets and other java classes
in a package ?

For the most part... Tomcat used to put them in a default package for you (or was that the jre doing it?) but no longer does. I think you can still get away with unpackaged servlets.
It makes sense to use packages anyway so, rather than get hung up on what containers need them and what kinds of classes need them, always package your classes.


Also do we need to add anything in the web.xml files for
the helper java classes and the javabeans ?

No, just put the classes in the correct place and the container will find them.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its is necessary to have all the servlets and other java classes
in a package ?


Yes. It's good practice in any Java envrionment, but mandatory in web apps.
 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read the jsp tutorial, I had come across something like :

<jsp:useBean id="user" class="classname" scope="session"/>

Is this used only when we need to specify the scope of the bean that is being used ?

Thanks so much.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here:
http://csajsp-chapters.corewebprogramming.com/CSAJSP-Chapter13.pdf

It will probably answer all of your questions, even the ones you haven't thought to ask yet ;-)

Good luck.
-Ben
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!