• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

java.lang.ClassNotFoundException: arjuncodes.DemoServlet

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using latest JRE 21 and latest eclipse EE.

My project Structure:

-Java Resources
  >src/main/java
     >arjun codes
        >DemoServlet.java
-src
 >main
       >java
         >arjuncodes
           >DemoServlet.java
       >webapp
          >META-INF
          >WEB-INF
              >lib
              >web.xml
          >index.jsp

codes:

index.jsp




DemoServlet.java


web.xml

within <web-app>:






Error: When i enter 2 numbers and then click on submit, this is the error:

Error in browser: Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


Error in eclipse debugger:
java.lang.ClassNotFoundException: arjuncodes.DemoServlet

Conclusion: clearly its not able to find DemoServlet class, but I cant figure out what else path name i could have given in <servlet-class> in web.xml (refer the code above for web.xml).

I am learning servlets and jsp so please bear with me.

Much thanks and Regards

I am expecting that after clicking on submit, it should redirect to page and sum should be written on this new redirected page
 
Saloon Keeper
Posts: 15276
350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you put a package statement above your servlet class?
 
Khushi Sing
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I have added package statement

package arjuncodes;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoServlet extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException {
int i=Integer.parseInt(req.getParameter("num1"));
int j=Integer.parseInt(req.getParameter("num2"));
int k=i+j;
PrintWriter out=res.getWriter();
out.println("Result is "+k);
}
}
 
Saloon Keeper
Posts: 7552
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're only showing the directory layout of the source code. After building the project, is the DemoServlet.class file in the directory WEB-INF/classes/arjuncodes?
 
Saloon Keeper
Posts: 27494
195
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you've arranged your project in Maven format, what Maven goal(s) are you invoking?
 
Ranch Hand
Posts: 202
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a wild guess (5 min before midnight):

Can it be that in your web project older servlets from javax.* packages are used and the test server in Eclipse has already new jakarta JavaWeb setup? I don't recall what error messages one gets in this case i.e. whether the exception is java.lang.ClassNotFoundException.
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic