aspose file tools*
The moose likes Servlets and the fly likes File upload - Error 404 -  servlet not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "File upload - Error 404 -  servlet not available " Watch "File upload - Error 404 -  servlet not available " New topic
Author

File upload - Error 404 - servlet not available

chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello,
I am trying to upload a file on Apache2.2.3 - mod_jk/1.2.19 - Tomcat5.5.20

On form submit, it's posted to http://www.knobe.org/Fupload/servlet/UServlet

httpd of Apache is having the line
JkMount /Fupload/* example

webapps/Fupload/WEB-INF/web.xml is having the entry
<servlet>
<servlet-name>UServlet</servlet-name>
<servlet-class>UServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>UServlet</servlet-name>
<url-pattern>/servlet/UServlet</url-pattern>
</servlet-mapping>

The UServlet.class is in webapps/Fupload/WEB-INF/classes/

The conf/server.xml is having the entry
<Context path="/Fupload" docBase="Fupload"
debug="0" privileged="true"
reloadable="true" >
</Context>

but am getting the 404 error - 'Servlet UServlet is not available'.
What could be the reason? What other enteries do i need?

Pl help. Thanks
gthri

[ October 26, 2006: Message edited by: chelakkad ]

[ October 26, 2006: Message edited by: chelakkad ]
[ October 27, 2006: Message edited by: chelakkad ben ]
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Try this: put your servlet in any package and refer it with fully qualified name in web.xml.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

"cb gthri",

You have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hi
I still find the error coming on. Anything wrong with my configuration?
Where did i go wrong?
rgds
ben
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If your app is in the webapps directory, you don't need to configure your server.xml. Are other servlets in you app working?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello Ben,
Yes, the appl is in webapps directory. The .class file is in
webapps/Fupload/WEB-INF/classes/
This is my first appl. The jsp-examples and servlets-examples are working fine.

gthri
[ October 27, 2006: Message edited by: chelakkad ben ]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hi
If however the Tomcat is restarted, an exception error is given...

javax.servlet.ServletException: Class UploadServlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)....

but this same servlet was working when Tomcat was first installed.
What could then be the reason?

rgds
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Post the class signature for your UploadServlet.
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello Ben,
What do you mean by class signature?...starting portion?
rgds
gthri
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
I see. seems like your "servlet" might not be a servlet after all. Did your servlet class implements javax.servlet.Servlet interface directly or indirectly through extending javax.servlet.http.HttpServlet?

Like our Ben said, you should post up your class signature, the one that starts with "public class xxx"

Cheers.


SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Ok... this is the code beginning...

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


public class UploadServlet extends HttpServlet {

String uploadDirectory="";
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
uploadDirectory = getServletContext().getRealPath("/WEB-INF/upload");

try {
......
is this enough?...in fact this code was working properly on another machine.....

gthri
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yep.
The following line is the class signature:
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

OK, your class is named "UploadServlet".

In your deployment descriptor, under the class attribute for this servlet, you're using:


They need to match.
Also, it is a good idea to package all of the Java classes in your webapp.
Once packaged, you will want to refer to your servlet with a fully qualified name:
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello
The problem exists even after spelling corrections.

gthri
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Using cut and paste (don't type them) post your corrected deployment descriptor, your servlet code and the HTML form that is posting to this servlet.
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hi Ben,

The html code...
----------------

<html>
<head></head>
<form name="fileupload" action="http://www.knobe.org/FileUpload/servlet/UploadServlet" method="post" enctype="multipart/form-data">
Choose file for uploading: <input type="file" name="file">
<br>
<input type="submit" value="Upload the file">
</form>
</html>


Deployment desc...in webapps/FileUpload/WEB-INF
-----------------------------------------------

<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>UploadServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/servlet/UploadServlet</url-pattern>
</servlet-mapping>
</web-app>

Servlet...in webapps/FileUpload/WEB-INF/classes
-----------------------------------------------


import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import CPIOConstants;
import CPIOInputStream;
import CPIOEntry;
import org.apache.commons.codec.binary.*;
import org.apache.commons.codec.*;


public class UploadServlet extends HttpServlet {

String uploadDirectory="";
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
uploadDirectory = getServletContext().getRealPath("/WEB-INF/upload");

try {
.......
.....


httpd
-----

...
...
LoadModule jk_module modules/mod_jk.so

<IfModule mod_jk.c>

JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

Alias /jsp-examples "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/jsp-examples/"

<Directory "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/jsp-examples/">
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</Directory>

Alias /servlets-examples "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/servlets-examples/"

<Directory "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/servlets-examples/">
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</Directory>


<Location /*/WEB-INF/*>
AllowOverride None
deny from all
</Location>

JkMount /jsp-examples/*.jsp example
JkMount /servlets-examples/* example
JkMount /FileUpload/* example

</IfModule>
...
...
The workers.properties is defined and is in conf directory.

The Error displayed...
----------------------

exception

javax.servlet.ServletException: Class UploadServlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
.....
.....


gthri
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

And you did compile the servlet, right?
The .class file is under WEB-INF/classes?
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hi Ben,
Thats right. The class file is in webapps/FileUpload/WEB-INF/classes folder.
The full error displayed when Tomcat is restarted is..

HTTP Status 500 -

type Exception report

message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: Class UploadServlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassCastException: UploadServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)

Subsequent calls to the servlet gives the error....

HTTP Status 404 - Servlet UploadServlet is not available

type Status report

message Servlet UploadServlet is not available

description The requested resource (Servlet UploadServlet is not available) is not available.

Any change req in web.xml?


gthri

[ October 31, 2006: Message edited by: chelakkad ben ]
[ November 01, 2006: Message edited by: chelakkad ben ]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Any modification needed in conf/httpd file?
gthri
[ November 01, 2006: Message edited by: chelakkad ben ]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello
Even a simple 'Hello world' servlet is giving the 500 error.
Can someone help?
gthri
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello,
Has anyone got any clue on this?

I wonder what's wrong with this servlet...


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

public class testservlet extends HttpServlet{

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
PrintWriter out;

resp.setContentType("text/html");
out = resp.getWriter();

out.println("<h1>Hello World</h1>");
}
}

because i still keep getting the error...

type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: Class testservlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter

is NOT a servlet!
Help!!
rgds
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Post your deployment descriptor.
Also give us a detailed explanation of where all of your files are.

If Tomcat still has it's own HTTP connector running, I would try to access it directly, once you know the servlet is running properly, then try accessing it through the connector via ApacheHttpd.

Before pasting any code or configuration pages to the forum, you might want to read.
http://faq.javaranch.com/view?AvoidRedHerrings
and possibly..
http://faq.javaranch.com/view?PostRealCode

It sounds like you're dealing with a very minor configuration problem.
This type of issue will be extremely hard for anyone on this list to spot if you are even a tiny bit sloppy in posting text to the forum.
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello Ben,

The deployment descriptor in folder webapps\testservlet\WEB-INF
----------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>testservlet</servlet-name>
<servlet-class>testservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testservlet</servlet-name>
<url-pattern>/servlet/testservlet</url-pattern>
</servlet-mapping>
</web-app>

The class file - testservlet.class , is in folder webapps\testservlet\WEB-INF\classes
---------------------------------------------------------------------------

Apache httpd is having the following entry...
--------------------------------------------

LoadModule jk_module modules/mod_jk.so

<IfModule mod_jk.c>

JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

Alias /jsp-examples "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/jsp-examples/"

<Directory "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/jsp-examples/">
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</Directory>

Alias /servlets-examples "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/servlets-examples/"

<Directory "D:/ApacheSoftwareFoundation/Tomcat5.5/webapps/servlets-examples/">
Options Indexes +FollowSymLinks
AllowOverride None
Allow from all
</Directory>


<Location /*/WEB-INF/*>
AllowOverride None
deny from all
</Location>

JkMount /jsp-examples/*.jsp example
JkMount /servlets-examples/* example
JkMount /testservlet/* example

</IfModule>

The mod_jk modules is in modules folder
---------------------------------------
D:\ApacheSoftwareFoundation\Apache2.2\modules


'Apache/2.2.3(Win32)mod_jk/1.2.19' is displayed in the status bar of the
Apache Service Monitor screen.

The following worked fine...
----------------------------
Published site knobe.org
http://www.knobe.org - the default page obtained
http://www.knobe.org:8080 - the default Tomcat page displayed
http://www.knobe.org/jsp-examples/ - defauls JSP examples page displayed
http://www.knobe.org/servlets-examples/ - displays default servlets examples page.Able to run the examples links in that page(eg. HelloWorld,functions ...etc)

and now this brings in the error...
-------------------------------
http://www.knobe.org/html/test.html - the page displayed with a submit button. POST to
action="http://www.knobe.org/testservlet/servlet/testservlet"
On clicking on the button the above mentioned error is displayed.

I hope it is now clear.
[ November 14, 2006: Message edited by: chelakkad ben ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Try:
http://www.knobe.org:8080/testservlet/servlet/testservlet
[ November 14, 2006: Message edited by: Ben Souther ]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello Ben,

Tried www.knobe.org:8080/testservlet/servlet/testservlet.
The first time after restarting Tomcat, i got this error

HTTP Status 500 -
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Class testservlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service
......
......
root cause

java.lang.ClassCastException: testservlet
org.apache.catalina.valves.ErrorReportValve.invoke
.....
.....

Second time onwards it is 404 error

HTTP Status 404 - Servlet testservlet is not available

type Status report

message Servlet testservlet is not available

description The requested resource (Servlet testservlet is not available) is not available.

rgds
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Put your servlet in a package. It should not be straight under classes.
Put it in a package, correct the java file, recompile, correct servlet-class web.xml and restart the container.


[My Blog]
All roads lead to JavaRanch
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
Hello
Is is necessary to put them in a package?
Even otherwise it has to work. In fact it worked once - the first time after installation.
rgds
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

sorry, I was note saying that it will work. But you should do it, as it will avoid you unexpected troubles.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File upload - Error 404 - servlet not available
 
Similar Threads
The requested resource (/mycode/AA) is not available
Servlet not available?
Servlet not being called
Problems with servlet-mapping to redirect some JSPs...
HTTP Status 404 - /myapps/helloworldservlet