• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call java class from jsp file  RSS feed

 
Neha Deshmukh
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am developing 1 web application for which I need to call some functions in .java file from .jsp file. I tried <%@page import="mypackage.myclass" %> but its saying ClassNotFound Exception.

Some details of application are:
I am using Weblogic 9.2.

I am deploying myjsp.jsp in \bea\weblogic92\samples\server\examples\build\mainWebApp\Trial\myjsp.jsp

.java file in

\bea\weblogic92\samples\server\examples\build\mainWebApp\Trial\mypackage

compiling this file as package (i.e. using javac -d ).
While compiling I am giving .class file to be generated in \bea\weblogic92\samples\server\examples\build\mainWebApp\WEB-INF\classes\mypackage\

Is this approch correct? as I am getting:

Error 500--Internal Server Error

java.lang.NoClassDefFoundError: mypackage/myclass

Please help me as soon as poosible.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha Deshmukh wrote:I am developing 1 web application for which I need to call some functions in .java file from .jsp file.

If this is the case, then you are following poor practices that have been discredited for over 8 years now. There should never be any Java code in a modern JSP. None. Ever.

Your page controller should perform all operations before forwarding to a JSP, in which only the JSTL and EL should be used.
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your location of classes appears to be correct.
Have you tried restarting the server?

Basically, your class file has to be under WEB-INF/classes in the correct package structure (which it appears to be)
Are your files getting deployed to the place where the server is running?

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