jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Unable to run a servlet from browser - 404 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to run a servlet from browser - 404 error" Watch "Unable to run a servlet from browser - 404 error" New topic

Unable to run a servlet from browser - 404 error

SJ Rao

Joined: Mar 05, 2003
Posts: 25
I have written a simple servlet program called Test1.java & the contents are
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Test1 extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
PrintWriter out = res.getWriter();
out.println("Hello world");
I am using weblogic 8.1 & have compiled & saved the class file in "C:\bea\user_projects\applications\mydomain\DefaultWebApp\WEB-INF\classes\TestProject\Test1.class".
My web.xml is as follows :-
The path of web.xml is "C:\bea\user_projects\applications\mydomain\DefaultWebApp\WEB-INF\web.xml"
When i run the servlet in the browser giving the path "http://localhost:7001/Test1" or any other combination, it is giving me 404 error.
Can someone pl. tell me where am going wrong ? Its very urgent.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
have you tried:
<a href="http://localhost:7001/<b rel="nofollow">TestProject</b>/Test1" target="_blank">http://localhost:7001/TestProject/Test1

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
SJ Rao

Joined: Mar 05, 2003
Posts: 25
Yes i did, but it is not working.
I have set the environment variable to "set classpath=%CLASSPATH%.;C:\bea\weblogic81\server\lib\weblogic.jar;"
After that, when i ran the servlet from the browser I am getting the error 500 - Internal server error.
Following is the error :-
javax.servlet.ServletException: [HTTP:101250][ServletContext(id=24724628,name=DefaultWebApp,context-path=)]: Servlet class TestProject.Test1 for servlet Test1 could not be loaded because a class on which it depends was not found in the classpath
java.lang.NoClassDefFoundError: TestProject/Test1 (wrong name: Test1).
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:800)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:504)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:349)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

Now atleast it is recognising the path, but donno if there is something very basic am missing
SJ Rao

Joined: Mar 05, 2003
Posts: 25
oh - i got it
I was doing a very silly mistake of not putting my code in package, due to which the server didnt know where to pick up the class file from...
It is sorta covered in the JavaRanch Style Guide.
subject: Unable to run a servlet from browser - 404 error
jQuery in Action, 3rd edition