This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes HTTP status 404 error on page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP status 404 error on page" Watch "HTTP status 404 error on page" New topic
Author

HTTP status 404 error on page

Sudhir Srinivasan
Ranch Hand

Joined: Jun 08, 2011
Posts: 90

Hi,

I'm a newbie to web programming and I've just started in the J2EE section of my java course. The first program relates to deploying an html file using servlet. While the following code worked at the course center, it does not do so when i tried the same at home.

Note: I've gone thru the other threads similar to this topic but could not find a satisfactory answer to the same and therefore starting a new thread.

I'm using netbeans IDE 6.0 to run the web application and the web server opted for, at the time of creation of project, is tomcat 6.0.

Web application details:
---------------------------
Project/application name: myWebApp
Package name: com.niit(in Source Packages directory)
Source code file path: Source Packages > com.niit > FirstServlet.java
html file path: Web Pages > WEB-INF > index.html


My program code:
--------------------



The html file generated is as follows:




The web.xml shows the following:



In the deployment descriptor, the servlet-name & url-pattern (preceded by /) are the same and the servlet-class contains the appropriate "package-name.class-name".

On running the html file, the web application tab of output window of IDE gives successful status as follows. Firefox browser then opens with the page containing 404 error. I entered the url http://localhost:8084/myWebApp/WEB-INF/index.html in IE but the page displays the same 404 status as shown on firefox.

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
Incrementally deploying http://localhost:8084/myWebApp
Completed incremental distribution of http://localhost:8084/myWebApp
run-deploy:
Browsing: http://localhost:8084/myWebApp/WEB-INF/index.html
run-display-browser:
run:
BUILD SUCCESSFUL (total time: 1 second)


while the server tab in the output window of IDE shows:

Using CATALINA_BASE: C:\Documents and Settings\Admin\.netbeans\6.0\apache-tomcat-6.0.14_base
Using CATALINA_HOME: C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14
Using CATALINA_TMPDIR: C:\Documents and Settings\Admin\.netbeans\6.0\apache-tomcat-6.0.14_base\temp
Using JRE_HOME: C:\Program Files\Java\jdk1.5.0_06
Jul 25, 2011 3:09:46 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_06\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\oracle\product\10.2.0\db_1\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Common Files\Microsoft Shared\Windows Live
Jul 25, 2011 3:09:46 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
Jul 25, 2011 3:09:46 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1631 ms
Jul 25, 2011 3:09:46 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jul 25, 2011 3:09:46 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
Jul 25, 2011 3:09:48 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base C:\Documents and Settings\Admin\My Documents\NetBeansProjects\WebApp\build\web does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:141)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3944)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4113)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jul 25, 2011 3:09:48 PM org.apache.catalina.core.StandardContext start
SEVERE: Error in resourceStart()
Jul 25, 2011 3:09:48 PM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Jul 25, 2011 3:09:48 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/WebApp] startup failed due to previous errors
Jul 25, 2011 3:09:48 PM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/WebApp] has not been started
Jul 25, 2011 3:09:48 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
Jul 25, 2011 3:09:48 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 25, 2011 3:09:48 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/109 config=null
Jul 25, 2011 3:09:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2234 ms
Jul 25, 2011 3:09:50 PM org.apache.catalina.core.StandardContext start
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myWebApp] has already been started


Does the above issue having anything to do with the jdk/jre (ver 1.5 on my computer) or windows network settings etc........

Would much appreciate answer(s) from the experts (if i've to go forward creating web apps).

thanks,
Sudhir
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

Sudhir Srinivasan wrote:I entered the url http://localhost:8084/myWebApp/WEB-INF/index.html in IE but the page displays the same 404 status as shown on firefox.
You can't directly access anything you stored in WEB-INF directory.

Sudhir Srinivasan wrote:<url-pattern>/FirstServlet</url-pattern>
Have you tried accessing http://localhost:8084/myWebApp/FirstServlet ?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Sudhir Srinivasan
Ranch Hand

Joined: Jun 08, 2011
Posts: 90

Thank you for your response.

Devaka Cooray wrote:Have you tried accessing http://localhost:8084/myWebApp/FirstServlet ?


I did as suggested and the page is now displayed.


Devaka Cooray wrote:You can't directly access anything you stored in WEB-INF directory.


I've been trying to run the index.html file instead of the servlet class file [FirstServlet.java]. As i've mentioned in my earlier post that i'm new to web programming and therefore could you please answer/explain the following:[this would enable me to have a good understanding of the fundamental concepts]

a) What is the WEB-INF directory and why is not possible to run files from this directory?
b) Is it possible to run the index.html file directly if it is created along with the servlet source file in the source packages directory of the IDE?
c) Is the very purpose of servlets to enable embedding of client programs [like html,css,javascript etc.] and run on the web server?


Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

Sudhir Srinivasan wrote:a) What is the WEB-INF directory and why is not possible to run files from this directory?

WEB-INF directory is the place where you can place your configuration files and the other files that should not be directly accessed by the URL. Since web.xml is stored inside the WEB-INF directory, users can't read the web.xml by directly accessing it through the URL. You can also have your JSPs and HTML files which should NOT be directly accessed by the URL, but to be accessed by the other components such as Servlets.

Sudhir Srinivasan wrote:b) Is it possible to run the index.html file directly if it is created along with the servlet source file in the source packages directory of the IDE?

Yes. In that case you should place your html file in the root directory - outside the WEB-INF directory.

Sudhir Srinivasan wrote:c) Is the very purpose of servlets to enable embedding of client programs [like html,css,javascript etc.] and run on the web server?

Nope. A Servlet is a component that runs in the servlet container - it has nothing to do with the "client programs". Have a look at this article to see the intended purpose of having a Servlet.


Sudhir Srinivasan
Ranch Hand

Joined: Jun 08, 2011
Posts: 90
Once again, thank you for your answers and the servlet article link.

I'm, however, facing the issue raised in my original post (& for which you've already responded). Please bear with me so that i can explain the same:

My faculty at the course center says that the index.html file (in the WEB-INF directory) should be run - i know this contradicts what you've answered - and not the servlet file. On running the html file, the browser opens with the page http://localhost:8084/myWebApp/WEB-INF/index.html containing the linked text (i've once again attached the html code below which shows the hyperlinked reference to the servlet "FirstServlet" with the text link).



Clicking the text link should lead to the page which displays the message from the html within the servlet (servlet source code and web.xml code attached).





Please Note: While the above works in the systems at the course center, it does not in my happen in my computer at home [
this is hampering practicing on my comp at home to keep pace with course-ware]. Could this be due to varying network / browser settings vis-a-vis course center Vs home comp OR any other reason.

My faculty suggested that the initial (html) page throws up a 404 error possibly due to third-party anti-virus (firewalls) in my comp and temporarily disable them before running the html file. I did the same but the result is the 404 page displayed.

Any solution from you much appreciated.


Sudhir Srinivasan
Ranch Hand

Joined: Jun 08, 2011
Posts: 90

Have resolved the issue........the html file should be in the Web pages directory of the IDE (instead of the WEB-INF directory) as suggested by the moderator earlier.........tied myself in knots unnecessarily.

regards,
Sudhir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP status 404 error on page