• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
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
 
Bartender
Posts: 15737
368
  • 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);
}
}
 
Bartender
Posts: 7645
178
  • 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: 28482
210
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?
 
Saloon Keeper
Posts: 235
7
Android Python Oracle Postgres Database 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.
 
It's just a flesh wound! Or a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic