• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File upload - Error 404 - servlet not available

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this: put your servlet in any package and refer it with fully qualified name in web.xml.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I still find the error coming on. Anything wrong with my configuration?
Where did i go wrong?
rgds
ben
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your app is in the webapps directory, you don't need to configure your server.xml. Are other servlets in you app working?
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the class signature for your UploadServlet.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ben,
What do you mean by class signature?...starting portion?
rgds
gthri
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep.
The following line is the class signature:
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
The problem exists even after spelling corrections.

gthri
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you did compile the servlet, right?
The .class file is under WEB-INF/classes?
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any modification needed in conf/httpd file?
gthri
[ November 01, 2006: Message edited by: chelakkad ben ]
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
Even a simple 'Hello world' servlet is giving the 500 error.
Can someone help?
gthri
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try:
http://www.knobe.org:8080/testservlet/servlet/testservlet
[ November 14, 2006: Message edited by: Ben Souther ]
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, I was note saying that it will work. But you should do it, as it will avoid you unexpected troubles.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic