Reputation: 15702
I have developed a Java web application using Tomcat 7
and Oracle JDK 1.7
with NeatBeans 7.3
. My application runs on my local pc without any errors.
But after i hosted my application, I can't access servlets. It is giving me 404
error. I'm not used web.xml
in my application to map servlets. I used annotation
for it.
Hosted server use Tomcat 7
and Open JDK 1.7
.
What could be the issue ? How can i solve this ?
New Update
The place where i have purchased hosting gave me cPanel
to upload files. There is no place to upload war
file or place to upload files in to webapps
director in tomcat. so i uploaded files in to public_html
directory. i think this may be the issue. because when i'm trying to access servlet like www.mysite.com/A
, server search for this in root
directoy. but acctually it is not there. so it gives 404
error.
I thnik this may be the issue. Any suggesions ?
UPDATED
Annotation is like below
@WebServlet(name = "AddCustomer", urlPatterns = {"/AddCustomer"})
Download Servlet from DropBox.
Directory structure.
Upvotes: 0
Views: 4573
Reputation: 10714
I had this same problem, it was caused by two different classes annotated with the same name: @WebServlet(name = "SameName", value = { "/path/to/use" })
Even though the value
was different, the name
was the same, and Tomcat seems to have not logged anything regarding this, instead just returning 404 when requested.
Upvotes: 0
Reputation: 44813
check the following:
Finally maybe post part of you web.xml and what url you are calling
Edit
So this is your code tree, but what has been deployed to your tomcat webapp directory? Are your compiled classes under WEB-INF?
Edit Do you new information received about the webapp being hosted in public_html I suggested you contact the resources of you hosted server provider to find out how to deploy correctly - maybe it is not even possible.
You could try getting a year long trial of EC2 from Amazon
Upvotes: 0
Reputation: 2416
Annotations don't work "out-of-the-box", you still have to tell
the Tomcat to look for annotated Servlet
classes. And to do that you need to use the correct version of the web.xml
:
<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_3_0.xsd"
version="3.0">
I haven't used NetBeans, but like Eclipse it probably has project properties that let you specify Dynamic Web Project facet to Servlet 3.0 value which gets translated to the web.xml
line shown above.
You should check your project's WEB-INF
folder for web.xml
or try exporting it properly - a WAR file should (must?) contain WEB-INF/web.xml
file.
You "tell it" by using Servlet 3.0 version in the web.xml
header. For earlier versions Tomcat won't expect annotation-marked servlets, i.e. you would have to list them manually in the XML.
As for the updated problem - you are getting 404 because the Apache HTTP Server (probably that is what is installed) doesn't understand WAR or JSP files, you need to configure it to forward the requests to the Tomcat which is probably on another port (default is 8080) - this is known as AJP or HTTP proxy, i.e. Apache server is acting as a front-side proxy to Tomcat. There are manny answers on that subject here at Stackoverflow.
You don't deploy a WAR file to public_html
because that's where PHP or Perl webapps are deployed.
You should check with your hosting provider if you really have Tomcat installed, at which port is it and where to deploy your Java web application.
Upvotes: 0
Reputation: 3212
After deploying your project in to tomcat check in to "tomcat7\work\Catalina\localhost\your app" if the classes are present into the location. If classes are there then it should not be the issue.
Upvotes: 0