aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

Unable to run a servlet from browser - 404 error

SJ Rao
Greenhorn

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 :-
<web-app>
<servlet>
<servlet-name>Test1</servlet-name>
<servlet-class>TestProject.Test1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test1</servlet-name>
<url-pattern>/Test1</url-pattern>
</servlet-mapping>
</web-app>
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.
Thanks
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
Greenhorn

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
C:\bea\user_projects\applications\mydomain\DefaultWebApp;C:\bea\user_projects\applications\mydomain\DefaultWebApp\WEB-INF\classes.
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
Greenhorn

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...
 
Don't get me started about those stupid light bulbs.
 
subject: Unable to run a servlet from browser - 404 error
 
Similar Threads
Problem with webapplication during deploying
Error 404- not found
"http://localhost:7001" on browser gives Error:404 ????
Deploying first JSP in Weblogic
How to run Servlets with Weblogic 6.1