Tomcat server at cPanel hosting giving 404 error after attempting to upload loose files into public_html, couldn't upload a war file
Asked Answered
B

4

0

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.

img

Beatnik answered 4/10, 2013 at 4:49 Comment(8)
is tomcat properly running ? are u able to open tomcat homepage?Abruption
@Beatnik 404 means file not found,so check your code properlyLashondra
@JunedAhsan yes. i can access jsp files in my application. but i can't access servlets.Beatnik
@javaBeginner My app running on my local pc without errors. i got this error after hosting my app on another server.Beatnik
@Beatnik can u share the path where you have deployed your application under tomcat. Also share the dir structure of your webappAbruption
@JunedAhsan looks likes an annotated servlet problemArtel
@user2310289 i doubt because he says it works fine in eclipse+tomcat environment. So if he is using the same tomcat7 with the same application on any machine, it should work.Abruption
@JunedAhsan I'll update you ASAP. there is a some problem with my internet connection right now :(Beatnik
A
0

check the following:

  • is the app below tomcat/webapps
  • can you see it from tomcat manager
  • any errors in the logs

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

Artel answered 4/10, 2013 at 4:54 Comment(6)
I can access jsp files in my application. but i can't access servlets. I'm not used web.xml in my application to map servlets. I used annotation for it.Beatnik
so you are using servlet3? Maybe post your annotated servletArtel
I'll update you ASAP. there is a some problem with my internet connection right now :(Beatnik
Yes. I have compiled classes under WEB-INF.Beatnik
What URL are you using to try to access your servlet? What URL does work for JSPs?Dymoke
www.mysite.com/abc.jsp to access jsp. www.mysite.com/A to access servlet. I can access jsp. but can't access servlet.Beatnik
P
0

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.

Pye answered 4/10, 2013 at 8:32 Comment(0)
Q
0

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.

UPDATE

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.

Quipster answered 4/10, 2013 at 13:9 Comment(1)
"you still have to tell the Tomcat to look"... really? How are you telling Tomcat to look for annotations?Dymoke
N
0

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.

Normalize answered 2/7, 2024 at 22:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.