wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HTTP Status 404 - /ch1/Serv1/ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HTTP Status 404 - /ch1/Serv1/" Watch "HTTP Status 404 - /ch1/Serv1/" New topic
Author

HTTP Status 404 - /ch1/Serv1/

ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
hi all

from HFSJ chapter1 page 30 i tried servlet program
its compiling fine
but its showing

HTTP Status 404 - /ch1/Serv1/

type Status report

message /ch1/Serv1/

description The requested resource (/ch1/Serv1/) is not available.


my web.xml is

<?xml version="1.0" encoding="ISO-8851-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>


web.xml is in E:\tomcat\apache-tomcat-5.5.26\webapps\ch1\WEB-INF\web.xml

i dont know where i did mistake

please someone help

thank you
Dee Brown
Ranch Hand

Joined: Jun 14, 2008
Posts: 94
Just a guess, but what happens when you use, " <url-pattern>/ch1</url-pattern>" and provided the fully qualified class in " <servlet-class>Ch1Servlet</servlet-class"?
Pham Hoai Van
Greenhorn

Joined: May 20, 2008
Posts: 15
check your url-partern vs requested url. Do they match?
[ June 17, 2008: Message edited by: Pham Hoai Van ]
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

where you put this (compiled servlet) class file ? means in which folder.

this should be under WEB-INF classes folder. [ WEB-INF/classes ]


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
hi Saifuddin

Ch1Servlet.class is under

E:\tomcat\apache-tomcat-5.5.26\webapps\ch1\WEB-INF\classes\Ch1Servlet.class
Dee Brown
Ranch Hand

Joined: Jun 14, 2008
Posts: 94
Someone indicated the url-patten should match the path in your browser. So if you are using, 'http://.../ch1/Serv1/" to access the resource, I believe the pattern should also be "/ch1/Serv1/ (not just ch1).
Jan Sterk
Ranch Hand

Joined: Jun 06, 2008
Posts: 139
-What url exactly did you type in the browser?
-Did you restart tomcat?


SCJP 1.4 (81%)<br />SCWCD 5 (95%)
ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
ya, i tried ch1/Serv1 too
but its not working

i restarted the tomcat and the url is http://localhost:8080/ch1/Serv1
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Any thing show up in the log file?

Tomcat writes text log files to the TOMCAT_HOME/logs directory.
ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
hi Saifuddin

can you please tell me how to look through in the log files
please guide me


catalina.2008-06-18
Jun 18, 2008 9:57:27 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
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.6.0_06\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_06\bin;
Jun 18, 2008 9:57:30 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 18, 2008 9:57:30 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 12656 ms
Jun 18, 2008 9:57:32 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 18, 2008 9:57:32 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.26
Jun 18, 2008 9:57:33 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 18, 2008 9:57:44 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 18, 2008 9:57:49 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 18, 2008 9:57:49 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/63 config=null
Jun 18, 2008 9:57:49 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 18, 2008 9:57:49 AM org.apache.catalina.startup.Catalina start



localhost.2008-06-18
Jun 18, 2008 9:57:38 AM org.apache.catalina.core.ApplicationContext log
INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
Jun 18, 2008 9:57:41 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jun 18, 2008 9:57:41 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jun 18, 2008 9:57:42 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jun 18, 2008 9:57:42 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()


thank you
ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
hi all

thank you all. its working fine now.
thanks a lot.
Dee Brown
Ranch Hand

Joined: Jun 14, 2008
Posts: 94
Someone should code up what is trying to be accomplished as paste it here or email it to the thread owner. If it is not done later today (it is 12:30 AM here), I can do it later. Also, the thread owner should verify that the built-in examples run. These should be at: "http://localhost:8080/examples/servlets/". I am at tomcat version 6.x so the location my be different if you are using version 5.x
Juwonlo Ibigbami
Ranch Hand

Joined: Nov 03, 2006
Posts: 83
Ks Karthe,
How did you do it? what makes it work? To me i guess you servlet name has an issue. i mean a serlet name with a space, "Chapter1 Servlet". how does it look?
i.e.

_________________________________________________________
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
_________________________________________________________


Juwonlo
SCJP 5.0
ks karthe
Greenhorn

Joined: Jun 17, 2008
Posts: 14
hi Juwonlo Ibigbami

i think servlet name is justt to link the servlet element with the mapping element.

and my actual problem is with the servlet.
after implementing the doGet properly it works fine.
very silly mistake made me spend a whole day.

thank you
Madhura Choudhary
Greenhorn

Joined: Oct 22, 2008
Posts: 9
Hi ks karthe

I have similar problem while running the servlet

HTTP Status 404 - /ch1/

----------------------------------------

type Status report

message /ch1/

description The requested resource (/ch1/) is not available.

------------------------------------------------
Please tell me how did you solved this problem.

Thanks in advance.
[ December 02, 2008: Message edited by: Madhura Choudhary ]

SCJP 1.6
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 457

Hi Madhura,

Can you paste your web.xml mapping and the full url you are trying to access in your browser here?


Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Madhura Choudhary
Greenhorn

Joined: Oct 22, 2008
Posts: 9
Hi Sai,

My web.xml is,
-------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>Chapter1Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
<servlet-mapping>

<web-app>

------------------------------------------------------------

web.xml is in
C:\Program Files\apache-tomcat-6.0.14\webapps\ch1

the url pattern is,
http:\\localhost:8080\ch1\Serv1

I tried changing my web.xml url pattern to,
<url-pattern>ch1/Serv1</url-pattern>
but still the same problem

Please tell me where i am going wrong ?

Thanks for helping.
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

Hi ks kathe,

You stated the solution to your 404 problem is:

and my actual problem is with the servlet. after implementing the doGet properly it works fine. very silly mistake made me spend a whole day.

And your original post stated the following problem:

description The requested resource (/ch1/Serv1/) is not available.

Perhaps you can clarify what the real solution/real problem was, because if you don�t implement the correct method in the servlet you will the following 405 error (not 404):

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

Therefore what I getting at is that the 404 error resource not available is NOT solved by implementing the doGet method, so perhaps you could clarify this as now a few developers might think that the �resource not available� error is solved by implementing the doGet method and this isn�t the case.
[ December 03, 2008: Message edited by: Justin Rundle ]
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

Hi Madhura Choudhary,

You are reciecving a 404 error for the requested resource (/ch1/Serv1) is not available, because your web.xml is invalid. Double-check your closed tags:

<servlet-mapping>
<servlet-name>Chapter1Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
<servlet-mapping>

Should be:
</servlet-mapping>
Madhura Choudhary
Greenhorn

Joined: Oct 22, 2008
Posts: 9
Thanks Justin Rundle,

I have made the correction but still i am getting the same error.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>Chapter1Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>

</web-app>
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

Does your servlet definitely exist in WEB-INF/class dir? And the servlet class is definitely called Ch1Servlet.class?
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

Madhura: you said your web.xml is in:
C:\Program Files\apache-tomcat-6.0.14\webapps\ch1

It should be in:
C:\Program Files\apache-tomcat-6.0.14\webapps\ch1\WEB-INF\
Madhura Choudhary
Greenhorn

Joined: Oct 22, 2008
Posts: 9
Hey Justin Rundle ,

After putting my web.xml inside WEB-INF its working. Really very silly mistake i had made.
Thanks a lot for helping me out
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

No probs, but I guess from here on in you'll never forget
Madhura Choudhary
Greenhorn

Joined: Oct 22, 2008
Posts: 9
Nope...Never
Jeena Jeen
Ranch Hand

Joined: Feb 11, 2009
Posts: 47
Hi i have exactly the same problem. I changed my web.xml also. Now it looks like:


My ch1Servlet class looks like following:


And the class file is in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\classes\ch1Servlet.class
And web.xml is in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\web.xml

I get the same error Http Status 404 : The requested resource () is not available.
I checked both the files these seems ok to me.
Can anyone please guide me.
Thanks
danish mansoor
Greenhorn

Joined: Mar 14, 2009
Posts: 2
Hi evryone, i too have the same problem. i have taken into consideration the complete instruction given in the above posts. Then also i m getting Error like this:

HTTP Status 404 -

--------------------------------------------------------------------------------

type Status report

message

description The requested resource () is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.27


the web.xml file is:
<?xml version="1.0" encoding="ISO-8851-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Chapter1Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>

and it is stored in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\

the Ch1Servlet.class file is:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Ch1Servlet extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException{

PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>"+
"<body>"+
"<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+"<br>"+today+"</body>"+"</html>");

}

}

and it is stored in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\classes\

please help i have wasted alot of time on it
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The first thing I'd try would be to put the servlet in a package. Leaving servlets or anything else in the default package is not recommended. So retry after putting the servlet in a package.

web.xml


Ch1Servlet.java


C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\classes\servlets\Ch1Servlet.class

http://localhost:8080/ch1/Serv1


[My Blog]
All roads lead to JavaRanch
Chithra Salam
Greenhorn

Joined: Mar 21, 2006
Posts: 19
Hi,

Change the web.xml, put encoding="ISO-8859-1" instead of encoding="ISO-8851-1".Try it out.

Chithra Salam
danish mansoor
Greenhorn

Joined: Mar 14, 2009
Posts: 2
Thanks alot Chithra. by changing the ISO-encoding in web.xml the way you said my first servlet program started working. but what was the reason behind it ?
Thanks alot once again and sorry for my late reply(because of my faulty internet connection) .
Abdul Rahman
Ranch Hand

Joined: Jul 04, 2008
Posts: 63
hi everyone,

even i've the same problem.

i'm trying to run a servlet example. i'm getting a blank page after clicking submit button. Please help.

Login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>SCWCD_Example_1_3</title>
</head>
<body>
<h3>Please enter your userid and password to see your account statement:</
h3>


<form action="LoginServlet" method="POST">
Userid : <input type="text" name="userid">


Password : <input type="password" name="password">


<input type="submit" value="Show Statement">
</form>
</body>
</html>

LoginServlet.java
public class LoginServlet extends HttpServlet {

Hashtable users = new Hashtable();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
String userid=request.getParameter("userid");
String pword =request.getParameter("password");
if(userid !=null && pword !=null && pword.equals(users.get(userid))){
request.setAttribute("userId", userid);
ServletContext sc= getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/AccountServlet");
rd.forward(request, response);
return;
}else{
RequestDispatcher rd = request.getRequestDispatcher("/login.html");
rd.forward(request, response);
return;
}
}
public void init() throws ServletException{
users.put("user1", "aaa");
users.put("user2", "bbb");
users.put("user3", "ccc");
}
}
web.xml
<servlet>
<description>wcd test project</description>
<display-name>wcd test project</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.example.servlets.LoginServlet</servlet-class>
</servlet>
<servlet>
<description>wcd test project</description>
<display-name>wcd test project</display-name>
<servlet-name>AccountServlet</servlet-name>
<servlet-class>com.example.servlets.AccountServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AccountServlet</servlet-name>
<url-pattern>/AccountServlet</url-pattern>
</servlet-mapping>

AccountServlet.java
public class AccountServlet extends HttpServlet {

Hashtable data = new Hashtable();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
String userId = (String)request.getAttribute("userid");
if(userId!=null){
String[] records = (String[])data.get(userId);
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println("<h3>Account Status for "+userId+" at the start of prev 3 months");
for(int i=0;i<records.length;i++){
out.println(records[i]+">
");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
public void init() throws ServletException {
data.put("ann", new String[]{ "01/01/2002 : 1000.00",
"01/02/2002 : 1300.00", "01/03/2002 : 900.00"} );
data.put("john", new String[]{ "01/01/2002 : 4500.00",
"01/02/2002 : 2100.00", "01/03/2002 : 2600.00"} );
data.put("mark", new String[]{ "01/01/2002 : 7800.00",
"01/02/2002 : 5200.00", "01/03/2002 : 1900.00"} );
}

}
Please note that i've checked all the below mentioned checkpoints:
1- the classes are in WEB-INF/classes/com/example/servlets/*.class
2- the web.xml is in WEB-INF directory.
3-the logs in the tomcat shows no error

please advise where i'm missing something...


Abdul
SCJP5, SCWCD5, [scwcd wall of fame]
Abdul Rahman
Ranch Hand

Joined: Jul 04, 2008
Posts: 63
the above code works fine if i replace the servlet name with some jsp (directly under the webroot), the requestdispatcher is working fine.
it doesn't work for servlets alone. is there something i'm missing wrt RequestDispatcher methods ?
WV Johnson
Greenhorn

Joined: Mar 26, 2009
Posts: 1
Chithra Salam wrote:Hi,

Change the web.xml, put encoding="ISO-8859-1" instead of encoding="ISO-8851-1".Try it out.

Chithra Salam


I was having this same problem described in this thread and could not get the Ch1Servlet to run on my Windows Vista laptop with Tomcat 6.0.18.
This change worked (in web.xml making the encoding="ISO-8859-1" instead of encoding="ISO-8851-1") and the Ch1Servlet runs.

Why did this fix the problem? How would I troubleshoot this? Which Tomcat log file would have info as to why the deployment failed?

Why not just always use "UTF-8" as the encoding? That seems to be the most standard and inclusive encoding so why even bother with anything else?

The Tomcat admin simply said "FAIL - Application at context path /ch1 could not be started", not much help to troubleshoot the problem.

Thanks for helping a newbie out



Mark Bridges
Greenhorn

Joined: Aug 24, 2009
Posts: 1
It's a common mistake. As I understand it ISO-8851-1 is not a valid encoding as it references the ISO standard for the "Determination of moisture, non-fat solids and fat contents for Butter". Consequently, Tomcat chokes attempting to read the URI encoding declared in your web.xml. As for the UTF-8 question, it's really just a matter of the fact the the Tomcat standard defaults to ISO-8859-1 and utilizing UTF-8 requires a minor change to the Connector configuration in your server.xml.

Hope this helps.
Darshan Shroff
Greenhorn

Joined: Nov 25, 2009
Posts: 12

Hi All,

The recent replies are correct.
Changing the encoding scheme from "ISO-8851-1" to "ISO-8859-1" works.
I believe its a typo in the Head First Servlets and JSP book. Its present in the second edition.

As someone rightly referred, "ISO-8851-1" specifies the routine method for the determination of the moisture content of butter. Wonder how that's related to us in the Java fraternity.

And Johnson, one could also debug this error easily by having a look at the log files at
CATALINA_HOME\logs\catalina.YYYY-MM-DD

One gets an error like below :-


Regards,
Darshan Shroff
shroffdarshan@gmail.com
Vinay Noah
Greenhorn

Joined: May 01, 2011
Posts: 1
Chithra Salam wrote:Hi,

Change the web.xml, put encoding="ISO-8859-1" instead of encoding="ISO-8851-1".Try it out.

Chithra Salam


It fixed this issue for me... Thanks a lot but I would like to now the root cause.

Regards
Vinay Noah
Zsejk Ivanovic
Greenhorn

Joined: May 30, 2005
Posts: 1

Redundant reply, but still: changing the encoding from ISO-8851-1 to ISO-8859-1 did the trick.



Depressing error in the book.



-zsejk

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Status 404 - /ch1/Serv1/
 
Similar Threads
404 Error
I am not able to Run Head First servlet example
First Example Of HFServlets & JSP Not Working
Cannot get Servlets Demystified Problem
servlet deployment