Меню

Ошибка 404 при запуске tomcat

I downloaded Apache Tomcat 6.0.2
And created a new server in Eclipse

  1. New -> Server
  2. Select «Tomcat v6.0 Server», Next
  3. Tomcat Installation Directory -> Where I unzipped Apache Tomcat 6.0.2
  4. Finish

Then I start the server and go to http://localhost:8080/ to see if it works. And I get a 404 error.

I’ve already googled it and tried to find a solution. But none of those remedies seem to work.

Any thoughts on what the problem is?

Stu Thompson's user avatar

Stu Thompson

38k19 gold badges106 silver badges156 bronze badges

asked Jul 22, 2009 at 6:57

hello_world_infinity's user avatar

2

From the top of my head, I thought Eclipse started the tomcat server without anything in it, i.e. no web applications. You have to ‘run’ or actually deploy something in that Eclipse Tomcat server so you won’t get the 404s.

The fact that you do get 404 error messages indicates that Tomcat actually IS running. If you shut it down from Eclipse, you won’t get those 404’s anymore 😉

answered Jul 22, 2009 at 7:10

drvdijk's user avatar

If your wanting to see your Tomcat Server Homepage then you will need to specify the server path and deploy path. The default is set to Use workspace metadata (does not modify your Tomcat installation).

How to do it.

  1. Firstly open the Server’s view in Eclipse. (Window >> Show View >> Servers).
  2. Double click on your Tomcat Server to open the Server Overview.
  3. Then set the Server Locations to Use Tomcat installation (takes control of Tomcat installation). Save the changes.
  4. Restart your Server and then go to localhost:8080. This should open the Apache Tomcat Homepage for your server.

Hope this helps!

answered Apr 14, 2012 at 20:46

Shane Doyle's user avatar

Shane DoyleShane Doyle

1,0561 gold badge12 silver badges16 bronze badges

The error 404 appears when Tomcat can’t find the localhost.ser file.
In order to get rid of this follow these steps:
1) In Eclipse, right click on server —> Properties —> Click Switch Location —> Apply—>Ok
(This will switch the [workspace metadata] location to the installed Tomcat location.)
2) Then go back to server, double click it. This will open Overview tab. Under this tab goto —>Server Location —> Select Use Tomcat Installation combo box.

Now close it, save it and try run your server and then rerun the URL.

answered May 1, 2012 at 20:20

Sonu's user avatar

SonuSonu

511 silver badge1 bronze badge

I agree to drvdijk.

Go to «Servers» window, then select your Tomcat instance. Double.click here you will see the «overview» window. Here you can click on «Open launch configuration» to see your Tomcat arguments («Arguments» tab).

Look for the system property «-Dwtp.deploy». This directory is where your Tomcat is looking for installed web applications, i think you don’t have ROOT.war application here. Isn’t it? 🙂

Hope this will help you

answered Jul 22, 2009 at 7:35

sourcerebels's user avatar

sourcerebelssourcerebels

5,1201 gold badge32 silver badges52 bronze badges

answered Jul 24, 2009 at 15:23

Titi Wangsa bin Damhore's user avatar

The problem is just as drvdijk mentioned, in order to run a webapp on tomcat from eclipse, it needs to be «deployed» to it. This can be done by right clicking the tomcat server -> add and remove

Alternatively, you can try to startup your tomcat server outside of eclipse. Go to your command line and type

  $CATALINA_HOMEbinstartup.bat          (Windows)

  $CATALINA_HOME/bin/startup.sh           (Unix)

Where $catalina_home is the directory of where you installed tomcat

answered Jan 8, 2012 at 23:41

kumikoda's user avatar

kumikodakumikoda

6446 silver badges27 bronze badges

Launch your eclipse Run as administration:
For that right click on eclipse——> run as administration.
It works.

If it not works then again do same and then follow these steps:

  1. In Eclipse, right click on server —> Properties —> Click Switch
    Location —> Apply—>Ok
    (This will switch the [workspace metadata]
    location to the installed Tomcat location.)

  2. Then go back to server, double click it. This will open Overview
    tab. Under this tab goto —>Server Location —> Select Use Tomcat
    Installation
    combo box.

Now close it, save it and try run your server and then rerun the URL.

Panther's user avatar

Panther

3,2729 gold badges26 silver badges49 bronze badges

answered Dec 16, 2016 at 9:55

Ashish Anand's user avatar

1- double click on server
2- Make Sure You have switched correctly the directory for tomcat here

Before

enter image description here

After Fix
enter image description here

3- And Even if you do #2 above you may need do this here as well !

Again here !

enter image description here

answered Dec 19, 2017 at 20:20

shareef's user avatar

shareefshareef

9,00413 gold badges58 silver badges89 bronze badges

Also, notice if you have a duplicated WEB-INF in your path. Sometimes after update a maven project you may have this issue and Tomcat points to an empty folder.

Try to use Tomcat 9 Instead of Tomcat 10

Applications that run on Tomcat 9 and earlier will not run on Tomcat 10 without changes. Java EE based applications designed for Tomcat 9 and earlier may be placed in the $CATALINA_BASE/webapps-javaee directory and Tomcat will automatically convert them to Jakarta EE and copy them to the webapps directory. This conversion is performed using the Apache Tomcat migration tool for Jakarta EE tool which is also available as a separate download for off-line use.

Eric Aya's user avatar

Eric Aya

69k35 gold badges179 silver badges250 bronze badges

answered Jul 6, 2022 at 18:04

стасевич's user avatar

стасевичстасевич

2282 silver badges9 bronze badges

Details
Written by  
Last Updated on 05 November 2019   |   Print  Email

In Java web development with Tomcat, it’s very often that you get HTTP 404 error like this:

tomcat-error-404

The error code is HTTP 404 (not found) and the description is:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

This error means the server could not find the requested resource (JSP, HTML, images…) and returns HTTP status code 404. Most of the time, you can fix this error by correcting the URL. However, sometimes it’s not easy like that, making it is an annoying error.

Here I suggest some possible reasons and how to fix the error HTTP 404 in Java web development with Tomcat.

 

1. The URL is not handled by any Java servlets

You need to check URL mapping in your servlet classes to make sure the requested URL is actually handled by a servlet. For example:

@WebServlet("/view_book")
public class ViewBookServlet extends HttpServlet {
...
}

This servlet handles the URL /view_book. If the request URL is /view_books the server will raise HTTP 404 error. You can fix by either correcting the URL or correcting the URL mapping in the @WebServlet annotation.

In older Java web application, you have to check the web deployment descriptor file web.xml because a Java servlet can be mapped to URL via XML like this:

<servlet-mapping>
    <servlet-name>ViewBookServlet</servlet-name>
    <url-pattern>/view_book</url-pattern>
</servlet-mapping>

 

2. Java servlet forwarding to a resource that does not exist

In this case, the requested URL is handled by a Java servlet, but code in the servlet forwards to a resource (JSP, HTML…) which does not exist, as shown in the following screenshot:

tomcat-error-404-forwarding

The code in the servlet class would look like this:

String registerForm = "frontend/registerform.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(registerForm);
dispatcher.forward(request, response);

You can fix by correcting the forward path in the servlet, and make sure that the forwarded resource does actually exist in the given path.

 

3. URL is case-sensitive

Note that Tomcat treats URL as case-sensitive, for instance /Register is different than /register. So you need to check and use correct case for the letters in request URL.

Also pay attention to the webapp name in the URL, for instance http://localhost:8080/BookstoreWebsite/ is different than http://localhost:8080/BookStoreWebsite/

TIP: in Eclipse, you can right click on the project, then click Run As > Run on Server, the IDE will always use the correct name of the web application.

Finally, you should not let the user see the raw HTTP 404 error page rendered by the server. Instead, you should design your own user-friendly 404 error page – follow this tutorial: How to Handle Error for Java web applications.

You can also watch the video version below:

 

Other Java Servlet Tutorials:

  • Java Servlet Quick Start for beginners (XML)
  • Java Servlet for beginners (annotations)
  • Java Servlet and JSP Hello World Tutorial with Eclipse, Maven and Apache Tomcat
  • Handling HTML form data with Java Servlet
  • Java File Download Servlet Example

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.

Add comment

I integrated Tomcat 7 in Eclipse. When I start it using Eclipse, it shows that Tomcat is up and running, but when I go to http://localhost:8080 in my browser, it gives me following error:

HTTP Status 404 — /

type Status report

message /

description The requested resource (/) is not available.

Apache Tomcat/7.0.23

I tried changing the port in server.xml just in case if 8080 is used by another service, but it didn’t work either. How can I solve it?

BalusC's user avatar

BalusC

1.1m370 gold badges3584 silver badges3535 bronze badges

asked Dec 15, 2011 at 12:40

Vandan Patel's user avatar

4

What are you expecting? The default Tomcat homepage? If so, you’ll need to configure Eclipse to take control over from Tomcat.

Doubleclick the Tomcat server entry in the Servers tab, you’ll get the server configuration. At the left column, under Server Locations, select Use Tomcat installation (note, when it is grayed out, read the section leading text! 😉 ). This way Eclipse will take full control over Tomcat, this way you’ll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse. I only don’t see how that’s useful while developing using Eclipse.

enter image description here

The port number is not the problem. You would otherwise have gotten an exception in Tomcat’s startup log and the browser would show a browser-specific «Connection timed out» error page (and thus not a Tomcat-specific error page which would impossibly be served when Tomcat was not up and running!)

answered Mar 28, 2012 at 16:00

BalusC's user avatar

BalusCBalusC

1.1m370 gold badges3584 silver badges3535 bronze badges

8

Following steps helped me solve the issue.

  1. In the eclipse right click on server and click on properties.
  2. If Location is set workspace/metadata click on switch location and
    so that it refers to /servers/tomcatv7server at localhost.server
  3. Save and close
  4. Next double click on server
  5. Under server locations mostly it would be selected as
    use workspace metadata Instead, select use tomcat installation
  6. Save changes
  7. Restart server and verify localhost:8080 works.

Dirk's user avatar

Dirk

2,9421 gold badge37 silver badges40 bronze badges

answered May 6, 2015 at 9:48

Amey Haldankar's user avatar

Amey HaldankarAmey Haldankar

2,2031 gold badge26 silver badges22 bronze badges

2

Copy the ROOT (Default) Web App into Eclipse.

Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.

  • Go to C:apache-tomcat-7.0.27webapps, R-click on the ROOT folder and copy it.
  • Then go to your Eclipse workspace, go to the .metadata folder, and search for «wtpwebapps». You should find something like your-eclipse-workspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebapps (or …/tmp1/wtpwebapps if you already had another server registered in Eclipse).
  • Go to the wtpwebapps folder, right-click, and paste ROOT (say «yes» if asked if you want to merge/replace folders/files).
  • Then reload localhost:8080 to see the Tomcat welcome page.

ronalchn's user avatar

ronalchn

12.2k10 gold badges50 silver badges61 bronze badges

answered Sep 11, 2012 at 19:31

Paul Thomas's user avatar

I did what BalusC said but it was not enough for me, I had to clean the Tomcat workdirectory : ( Click right on right on Tomcat in the Servers Tab -> Clean Tomcat Work Directory )

answered Jan 5, 2015 at 10:36

walox's user avatar

waloxwalox

4911 gold badge7 silver badges24 bronze badges

Please check in your server specification again, if you have changed your port number to something else.
And change the port number in your link whatever new port number it is.

Also check whether your server is running properly before you try accessing your localhost.

answered Jan 31, 2012 at 8:18

Advait's user avatar

AdvaitAdvait

973 silver badges12 bronze badges

If you are new in JSP/Tomcat don’t modify tomcat’s xml files.

I assume you have already deployed web application. But to be sure, try these steps:
— right click on your web application
— select Run As / Run on Server, choose your Tomcat 7

These steps will deploy and run in the browser your application. Another idea to check if your Tomcat works correctly is to find path where tomcat exists (in eclipse plugin), and copy some working WAR file to webapps (not to wtpwebapps), and then try to run the app.

answered Jan 31, 2012 at 8:38

lukastymo's user avatar

lukastymolukastymo

25.8k14 gold badges53 silver badges66 bronze badges

If options under Server Locations are grayed out, note the message in the section title: «Server must be published with no modules present». To publish the server, right click the name of the server in the Server window and select «Publish».

answered Oct 28, 2012 at 17:03

kansasian's user avatar

Sometimes cleaning the server works. It worked for me many times.This is only applicable if the program worked earlier but suddenly it stops working.
Steps:
» Right click on Tomcat Server -> Clean. Then restart the server.»

answered Jan 10, 2016 at 15:37

Sourav Saha's user avatar

Sourav SahaSourav Saha

1432 silver badges12 bronze badges

0

I had the same problem with my localhost project using Eclipse Luna, Maven and Tomcat — the Tomcat homepage would appear fine, however my project would get the 404 error.

After trying many suggested solutions (updating spring .jar file, changing properties of the Tomcat server, add/remove project, change JRE from 1.6 to 7 etc) which did not fix the issue, what worked for me was to just Refresh my project. It seems Eclipse does not automatically refresh the project after a (Maven) build. In Eclipse 3.3.1 there was a ‘Refresh Automatically’ option under Preferences > General > Workspace however that option doesn’t look to be in Luna.

  1. Maven clean-install on the project.
  2. ** Right-click the project and select ‘Refresh’. **
  3. Right-click the Eclipse Tomcat server and select ‘Clean’.
  4. Right-click > Publish and then start the Tomcat server.

answered Oct 9, 2014 at 4:10

Gut Feeling's user avatar

1

In my case, I’ve had to click on my project, then go to File > Properties > *servlet name* and click Restart servlet.

answered Oct 2, 2020 at 10:47

GChuf's user avatar

GChufGChuf

75013 silver badges28 bronze badges

For me, my Eclipse installation was hosed — I think because I’d installed struts. After trying a dozen remedies for this error, I re-installed Eclipse, made a new workspace and it was OK. Using Kepler-64-Windows, Tomcat 7, Windows 7.

answered Apr 2, 2014 at 18:44

Kevin S. Miller's user avatar

Kevin S. MillerKevin S. Miller

8931 gold badge9 silver badges21 bronze badges

This worked for me:

  1. Project > Build Automatically (Make sure it’s turned on)
  2. Project > Clean …
  3. Right click Tomcat > Properties > General Tab > Switch Location (switch from workspace metadata to Server at localhost.server)
  4. Restart Eclipse
  5. Run Project As Server

answered Dec 13, 2017 at 15:14

Imran Ariffin's user avatar

Apache Tomcat/7.0.23 service is not loaded or enabled. Pls check the service status and other app which is using 8080 port currently. To check this use netstat command and observe whether another app is occupying the port 8080!

answered Jun 25, 2022 at 19:33

Ahad Mosharraf's user avatar

I integrated Tomcat 7 in Eclipse. When I start it using Eclipse, it shows that Tomcat is up and running, but when I go to http://localhost:8080 in my browser, it gives me following error:

HTTP Status 404 — /

type Status report

message /

description The requested resource (/) is not available.

Apache Tomcat/7.0.23

I tried changing the port in server.xml just in case if 8080 is used by another service, but it didn’t work either. How can I solve it?

BalusC's user avatar

BalusC

1.1m370 gold badges3584 silver badges3535 bronze badges

asked Dec 15, 2011 at 12:40

Vandan Patel's user avatar

4

What are you expecting? The default Tomcat homepage? If so, you’ll need to configure Eclipse to take control over from Tomcat.

Doubleclick the Tomcat server entry in the Servers tab, you’ll get the server configuration. At the left column, under Server Locations, select Use Tomcat installation (note, when it is grayed out, read the section leading text! 😉 ). This way Eclipse will take full control over Tomcat, this way you’ll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse. I only don’t see how that’s useful while developing using Eclipse.

enter image description here

The port number is not the problem. You would otherwise have gotten an exception in Tomcat’s startup log and the browser would show a browser-specific «Connection timed out» error page (and thus not a Tomcat-specific error page which would impossibly be served when Tomcat was not up and running!)

answered Mar 28, 2012 at 16:00

BalusC's user avatar

BalusCBalusC

1.1m370 gold badges3584 silver badges3535 bronze badges

8

Following steps helped me solve the issue.

  1. In the eclipse right click on server and click on properties.
  2. If Location is set workspace/metadata click on switch location and
    so that it refers to /servers/tomcatv7server at localhost.server
  3. Save and close
  4. Next double click on server
  5. Under server locations mostly it would be selected as
    use workspace metadata Instead, select use tomcat installation
  6. Save changes
  7. Restart server and verify localhost:8080 works.

Dirk's user avatar

Dirk

2,9421 gold badge37 silver badges40 bronze badges

answered May 6, 2015 at 9:48

Amey Haldankar's user avatar

Amey HaldankarAmey Haldankar

2,2031 gold badge26 silver badges22 bronze badges

2

Copy the ROOT (Default) Web App into Eclipse.

Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.

  • Go to C:apache-tomcat-7.0.27webapps, R-click on the ROOT folder and copy it.
  • Then go to your Eclipse workspace, go to the .metadata folder, and search for «wtpwebapps». You should find something like your-eclipse-workspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebapps (or …/tmp1/wtpwebapps if you already had another server registered in Eclipse).
  • Go to the wtpwebapps folder, right-click, and paste ROOT (say «yes» if asked if you want to merge/replace folders/files).
  • Then reload localhost:8080 to see the Tomcat welcome page.

ronalchn's user avatar

ronalchn

12.2k10 gold badges50 silver badges61 bronze badges

answered Sep 11, 2012 at 19:31

Paul Thomas's user avatar

I did what BalusC said but it was not enough for me, I had to clean the Tomcat workdirectory : ( Click right on right on Tomcat in the Servers Tab -> Clean Tomcat Work Directory )

answered Jan 5, 2015 at 10:36

walox's user avatar

waloxwalox

4911 gold badge7 silver badges24 bronze badges

Please check in your server specification again, if you have changed your port number to something else.
And change the port number in your link whatever new port number it is.

Also check whether your server is running properly before you try accessing your localhost.

answered Jan 31, 2012 at 8:18

Advait's user avatar

AdvaitAdvait

973 silver badges12 bronze badges

If you are new in JSP/Tomcat don’t modify tomcat’s xml files.

I assume you have already deployed web application. But to be sure, try these steps:
— right click on your web application
— select Run As / Run on Server, choose your Tomcat 7

These steps will deploy and run in the browser your application. Another idea to check if your Tomcat works correctly is to find path where tomcat exists (in eclipse plugin), and copy some working WAR file to webapps (not to wtpwebapps), and then try to run the app.

answered Jan 31, 2012 at 8:38

lukastymo's user avatar

lukastymolukastymo

25.8k14 gold badges53 silver badges66 bronze badges

If options under Server Locations are grayed out, note the message in the section title: «Server must be published with no modules present». To publish the server, right click the name of the server in the Server window and select «Publish».

answered Oct 28, 2012 at 17:03

kansasian's user avatar

Sometimes cleaning the server works. It worked for me many times.This is only applicable if the program worked earlier but suddenly it stops working.
Steps:
» Right click on Tomcat Server -> Clean. Then restart the server.»

answered Jan 10, 2016 at 15:37

Sourav Saha's user avatar

Sourav SahaSourav Saha

1432 silver badges12 bronze badges

0

I had the same problem with my localhost project using Eclipse Luna, Maven and Tomcat — the Tomcat homepage would appear fine, however my project would get the 404 error.

After trying many suggested solutions (updating spring .jar file, changing properties of the Tomcat server, add/remove project, change JRE from 1.6 to 7 etc) which did not fix the issue, what worked for me was to just Refresh my project. It seems Eclipse does not automatically refresh the project after a (Maven) build. In Eclipse 3.3.1 there was a ‘Refresh Automatically’ option under Preferences > General > Workspace however that option doesn’t look to be in Luna.

  1. Maven clean-install on the project.
  2. ** Right-click the project and select ‘Refresh’. **
  3. Right-click the Eclipse Tomcat server and select ‘Clean’.
  4. Right-click > Publish and then start the Tomcat server.

answered Oct 9, 2014 at 4:10

Gut Feeling's user avatar

1

In my case, I’ve had to click on my project, then go to File > Properties > *servlet name* and click Restart servlet.

answered Oct 2, 2020 at 10:47

GChuf's user avatar

GChufGChuf

75013 silver badges28 bronze badges

For me, my Eclipse installation was hosed — I think because I’d installed struts. After trying a dozen remedies for this error, I re-installed Eclipse, made a new workspace and it was OK. Using Kepler-64-Windows, Tomcat 7, Windows 7.

answered Apr 2, 2014 at 18:44

Kevin S. Miller's user avatar

Kevin S. MillerKevin S. Miller

8931 gold badge9 silver badges21 bronze badges

This worked for me:

  1. Project > Build Automatically (Make sure it’s turned on)
  2. Project > Clean …
  3. Right click Tomcat > Properties > General Tab > Switch Location (switch from workspace metadata to Server at localhost.server)
  4. Restart Eclipse
  5. Run Project As Server

answered Dec 13, 2017 at 15:14

Imran Ariffin's user avatar

Apache Tomcat/7.0.23 service is not loaded or enabled. Pls check the service status and other app which is using 8080 port currently. To check this use netstat command and observe whether another app is occupying the port 8080!

answered Jun 25, 2022 at 19:33

Ahad Mosharraf's user avatar

  1. HowTo
  2. Java Howtos
  3. Tomcat 404 Error
  1. Tomcat 404 Error in Java
  2. Tomcat 404 Error in Eclipse

Tomcat 404 Error

This tutorial demonstrates how to troubleshoot the Tomcat 404 error in Java.

Tomcat 404 Error in Java

While using the apache Tomcat server for web development in Java, the most common error is the HTTP Status 404. This error means the server cannot find the required resource.

The required file can be anything like HTML, Image Resource or JSP.

Most of the time, the error occurs when the required reference is not present or is referenced incorrectly. The error looks like this:

Tomcat 404 Error

There are three main reasons for this error in Apache Tomcat.

  1. The URL is Case Sensitive

    The Tomcat URLs are case sensitive, so whenever you are trying to write the URL by yourself, make sure that it is also correct in its case. Otherwise, it will throw the 404 status error.

  2. The Servlets Do Not Handle the URL

    The @Webservlet() is also used to handle the URL/demo, but when requesting the URL, it can be URL/this_demo, which is a different reference. This can be fixed by using the URL mapping and referencing the URL correctly.

    See example:

    @WebServlet("/demo")
    public class Demo extends HttpServlet {
    // Your code here.
    }
    

    Now, if the website requests the URL this_demo, we can solve it by changing the demo to this_demo in the URL mapping.

  3. Resource Forward by Servlets Does Not Exist

    When the resource forwarded by servlets does not exist, the Tomcat will throw a 404 error. Make sure the resource forwarded exists and the name of that resource is correct.

    For example, if we are referencing the DemoForm.jsp but the real name of that resource is Demo_Form.jsp, it will throw the 404 status error. We can change the DemoForm.jsp to Demo_Form.jsp to solve this error.

    See example:

    String Demo_Form= "frontend/Demo_Form.jsp";
    RequestDispatcher Request_Dispatcher = request.getRequestDispatcher(Demo_Form);
    Request_Dispatcher.forward(request, response);
    

Tomcat 404 Error in Eclipse

While working with Tomcat in Eclipse IDE, the same 404 error can occur even if we have managed all the solutions above. Sometimes, even if the Tomcat starts, the browser will throw the 404 error while working with Eclipse IDE.

This error is because Tomcat is not configured correctly in the Eclipse IDE. To solve this issue in Eclipse, follow the steps below.

  • Make sure Tomcat is downloaded and extracted.
  • Open the Eclipse IDE. Make sure you are using the EE version of Eclipse.
  • Go to the Servers tab in Eclipse, and if you see no Tomcat server, click create a new server. Or go to the Window menu, then Preferences and then Server and Add New.

    Tomcat Server Tab

    Tomcat Server Add

  • Select your version of Tomcat from the Apache folder on the page and click Next.

    Tomcat Server Add Apache

  • Click Browse and select your Tomcat directory. The installed JRE is okay if it works; otherwise, add the latest version. Click Next.

    Tomcat Server Add Path

  • Select your project and click Add and then Finish. A Tomcat server will be added to the Servers tab.

    Tomcat Server Added

  • Double click the Tomcat Server in the Servers tab, and a page will open. Under the Server Locations, select Use Tomcat Installation.
  • Save the configuration by Ctrl+S.
  • Restart the server, right-click on the server name in the Servers tab and click Restart.

    Tomcat Restart

  • Now the server works perfectly.

    Tomcat Started

Sheeraz Gul avatar
Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn
Facebook

Related Article — Java Error

  • Error Opening Registry Key ‘Software JavaSoft Java Runtime Environment.3’ in Java
  • Identifier Expected Error in Java
  • Error: Class, Interface, or Enum Expected in Java
  • Unreported Exception Must Be Caught or Declared to Be Thrown
  • Java.Lang.OutOfMemoryError: Unable to Create New Native Thread
  • Class Has Been Compiled by a More Recent Version of Java RuntimeEzoic
  • Содержание

    1. [Solved] Tomcat Error HTTP Status 404 Not Found
    2. Other Java Servlet Tutorials:
    3. About the Author:
    4. Tomcat 404 Error
    5. Tomcat 404 Error in Java
    6. Tomcat 404 Error in Eclipse
    7. HTTP Status 404 in Tomcat
    8. Comments
    9. Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available” [Answered]
    10. Sample problem:
    11. HTTP Status 404 — /servlet
    12. HTTP Status 404 — Not Found
    13. Answer #1:
    14. Introduction
    15. Put servlet class in a package
    16. Set servlet URL in url-pattern
    17. @WebServlet works only on Servlet 3.0 or newer
    18. javax.servlet.* doesn’t work anymore in Servlet 5.0 or newer
    19. Make sure compiled *.class file is present in built WAR
    20. HTTP Status 500
    21. Test the servlet individually without any JSP/HTML page
    22. Use domain-relative URL to reference servlet from HTML

    [Solved] Tomcat Error HTTP Status 404 Not Found

    The error code is HTTP 404 (not found) and the description is:

    The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    This error means the server could not find the requested resource (JSP, HTML, images…) and returns HTTP status code 404. Most of the time, you can fix this error by correcting the URL. However, sometimes it’s not easy like that, making it is an annoying error.

    Here I suggest some possible reasons and how to fix the error HTTP 404 in Java web development with Tomcat.

    1. The URL is not handled by any Java servlets

    You need to check URL mapping in your servlet classes to make sure the requested URL is actually handled by a servlet. For example:

    This servlet handles the URL /view_book . If the request URL is /view_books the server will raise HTTP 404 error. You can fix by either correcting the URL or correcting the URL mapping in the @WebServlet annotation.

    2. Java servlet forwarding to a resource that does not exist

    In this case, the requested URL is handled by a Java servlet, but code in the servlet forwards to a resource (JSP, HTML…) which does not exist, as shown in the following screenshot:

    The code in the servlet class would look like this:

    You can fix by correcting the forward path in the servlet, and make sure that the forwarded resource does actually exist in the given path.

    3. URL is case-sensitive

    Note that Tomcat treats URL as case-sensitive, for instance /Register is different than /register . So you need to check and use correct case for the letters in request URL.

    Also pay attention to the webapp name in the URL, for instance http://localhost:8080/BookstoreWebsite/ is different than http://localhost:8080/BookStoreWebsite/

    TIP: in Eclipse, you can right click on the project, then click Run As > Run on Server, the IDE will always use the correct name of the web application.

    Finally, you should not let the user see the raw HTTP 404 error page rendered by the server. Instead, you should design your own user-friendly 404 error page – follow this tutorial: How to Handle Error for Java web applications.

    You can also watch the video version below:

    Other Java Servlet Tutorials:

    Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.

    Источник

    Tomcat 404 Error

    This tutorial demonstrates how to troubleshoot the Tomcat 404 error in Java.

    Tomcat 404 Error in Java

    While using the apache Tomcat server for web development in Java, the most common error is the HTTP Status 404 . This error means the server cannot find the required resource.

    The required file can be anything like HTML, Image Resource or JSP.

    Most of the time, the error occurs when the required reference is not present or is referenced incorrectly. The error looks like this:

    There are three main reasons for this error in Apache Tomcat.

    The URL is Case Sensitive

    The Tomcat URLs are case sensitive, so whenever you are trying to write the URL by yourself, make sure that it is also correct in its case. Otherwise, it will throw the 404 status error.

    The Servlets Do Not Handle the URL

    The @Webservlet() is also used to handle the URL/demo , but when requesting the URL, it can be URL/this_demo , which is a different reference. This can be fixed by using the URL mapping and referencing the URL correctly.

    Now, if the website requests the URL this_demo , we can solve it by changing the demo to this_demo in the URL mapping.

    Resource Forward by Servlets Does Not Exist

    When the resource forwarded by servlets does not exist, the Tomcat will throw a 404 error. Make sure the resource forwarded exists and the name of that resource is correct.

    For example, if we are referencing the DemoForm.jsp but the real name of that resource is Demo_Form.jsp , it will throw the 404 status error. We can change the DemoForm.jsp to Demo_Form.jsp to solve this error.

    Tomcat 404 Error in Eclipse

    While working with Tomcat in Eclipse IDE, the same 404 error can occur even if we have managed all the solutions above. Sometimes, even if the Tomcat starts, the browser will throw the 404 error while working with Eclipse IDE.

    This error is because Tomcat is not configured correctly in the Eclipse IDE. To solve this issue in Eclipse, follow the steps below.

    Источник

    HTTP Status 404 in Tomcat

    I just posted a question about compiling a servlet and now I can compile a servlet successfully.

    But now I am having problem accessing my «world famous» HelloWorld servlet. My servlet is in webappsexercisesWEB-INFclasses directory.

    I am acessing my servlet like this:
    http://localhost:8080/exercises/servlet/HelloWorld

    but I am ending up with the following error: Can anyone tell me why am I getting this? Thanks!

    Have you turned on the invoker servlet?

    uncomment the lines in $TOMCATconfweb.xml

    this executes anonymous servlet classes that have not been defined in a web.xml file.

    alternatively you could start with correct procedures and add your hello world servlet to web.xml

    I get the same problem when I try to run my servlet. My servlet is in myappwebbuildWEB-INFclasses directory.

    I am acessing my servlet like this:
    http://localhost:8080/myapp/servlet/HelloWorld

    and I end up with the same error. I checked my web.xml file and the invoker servlet is already commented.

    Can anyone tell me what else could be going wrong?

    Thanks alot.
    Rana

    . (after being sure Tomcat is correctly configured [by getting the tomcat HTML page when hitting http://localhost:8080 ] on your browser. only after that).

    To solve the problem I had to modify the «conf/server.xml» by adding the code lines that follow just before (or near) the

    The lines of the logger generate a .txt file that record information on log details and errors that happened to be on every executable file under «PacoApps» every session Tomcat starts (half guess). The resulting file will be kept in the «%CATALINA_HOME/logs» folder under the name «localhost_PacoApps_log.txt» in my case.

    To let Tomcat see your servlet files you also have to uncomment the the following section in the «conf/web.xml» file (it is XML-commented at least in the jakarta-tomcat-4.1.24 version):

    invoker /servlet/*
    Probably you should restart Tomcat 2 or 3 times just to make shure changes are being considered. With those changes everything runs smoothly. Servlets run by hitting «http://localhost:8080/PacoApps/servlet/ServletName» on your browser, the JavaServer Pages by «http://localhost:8080/PacoApps/MyJSPExample.jsp», html pages by «http://localhost:8080/PacoApps/myPage.htm», etc.

    Hope this helps !

    EXTRA HINT: Watch out for comment tag nesting within XML files. Don?t put comment tags within comment tags. They can cause you some hard trouble. At least they did to me.

    Источник

    Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available” [Answered]

    Sample problem:

    I have an HTML form in a JSP file in my WebContent/jsps folder. I have a servlet class servlet.java in my default package in src folder. In my web.xml it is mapped as /servlet .

    I have tried several URLs in action attribute of the HTML form:

    But none of those work. They all keep returning a HTTP 404 error like below in Tomcat 6/7/8:

    HTTP Status 404 — /servlet

    Description: The requested resource (/servlet) is not available.

    Or as below in Tomcat 8.5/9:

    HTTP Status 404 — Not Found

    Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

    Why is it not working?

    Answer #1:

    Introduction

    This can have a lot of causes which are broken down in following sections:

    • Put servlet class in a package
    • Set servlet URL in url-pattern
    • @WebServlet works only on Servlet 3.0 or newer
    • javax.servlet.* doesn’t work anymore in Servlet 5.0 or newer
    • Make sure compiled *.class file is present in built WAR
    • Test the servlet individually without any JSP/HTML page
    • Use domain-relative URL to reference servlet from HTML
    • Use straight quotes in HTML attributes

    Put servlet class in a package

    First of all, put the servlet class in a Java package . You should always put publicly reuseable Java classes in a package, otherwise they are invisible to classes which are in a package, such as the server itself. This way you eliminate potential environment-specific problems. Packageless servlets work only in specific Tomcat+JDK combinations and this should never be relied upon.

    In case of a “plain” IDE project, the class needs to be placed in its package structure inside the “Java Sources” folder, not inside “Web Content” folder, which is for web files such as JSP. Below is an example of the folder structure of a default Eclipse Dynamic Web Project as seen in Navigator view (the “Java Sources” folder is in such project by default represented by src folder):

    In case of a Maven project, the class needs to be placed in its package structure inside main/java and thus not main/resources , this is for non-class files and absolutely also not main/webapp , this is for web files. Below is an example of the folder structure of a default Maven webapp project as seen in Eclipse’s Navigator view:

    Note that the /jsps subfolder is not strictly necessary. You can even do without it and put the JSP file directly in webcontent/webapp root, but I’m just taking over this from your question.

    Set servlet URL in url-pattern

    The servlet URL is specified as the “URL pattern” of the servlet mapping. It’s absolutely not per definition the classname/filename of the servlet class. The URL pattern is to be specified as value of @WebServlet annotation.

    In case you want to support path parameters like /servlet/foo/bar , then use an URL pattern of /servlet/* instead. See also Servlet and path parameters like /xyz//test, how to map in web.xml?

    @WebServlet works only on Servlet 3.0 or newer

    In order to use @WebServlet , you only need to make sure that your web.xml file, if any (it’s optional since Servlet 3.0), is declared conform Servlet 3.0+ version and thus not conform e.g. 2.5 version or lower. Below is a Servlet 4.0 compatible one (which matches Tomcat 9+, WildFly 11+, Payara 5+, etc).

    Or, in case you’re not on Servlet 3.0+ yet (e.g. Tomcat 6 or older), then remove the @WebServlet annotation.

    And register the servlet instead in web.xml like this:

    Note thus that you should not use both ways. Use either annotation based configuarion or XML based configuration. When you have both, then XML based configuration will override annotation based configuration.

    javax.servlet.* doesn’t work anymore in Servlet 5.0 or newer

    Since Jakarta EE 9 / Servlet 5.0 (Tomcat 10, TomEE 9, WildFly 22 Preview, GlassFish 6, Payara 6, Liberty 22, etc), the javax.* package has been renamed to jakarta.* package.

    In other words, please make absolutely sure that you don’t randomly put JAR files of a different server in your WAR project such as tomcat-servlet-api-9.x.x.jar merely in order to get the javax.* package to compile. This will only cause trouble. Remove it altogether and edit the imports of your servlet class from

    In case you’re using Maven, you can find examples of proper pom.xml declarations for Tomcat 10+, Tomcat 9-, JEE 9+ and JEE 8- in this answer: Tomcat casting servlets to javax.servlet.Servlet instead of jakarta.servlet.http.HttpServlet

    Make sure compiled *.class file is present in built WAR

    In case you’re using a build tool such as Eclipse and/or Maven, then you need to make absolutely sure that the compiled servlet class file resides in its package structure in /WEB-INF/classes folder of the produced WAR file. In case of package com.example; public class YourServlet , it must be located in /WEB-INF/classes/com/example/YourServlet.class . Otherwise you will face in case of @WebServlet also a 404 error, or in case of a HTTP 500 error like below:

    HTTP Status 500

    Error instantiating servlet class com.example.YourServlet

    And find in the server log a java.lang.ClassNotFoundException: com.example.YourServlet , followed by a java.lang.NoClassDefFoundError: com.example.YourServlet , in turn followed by javax.servlet.ServletException: Error instantiating servlet class com.example.YourServlet .

    An easy way to verify if the servlet is correctly compiled and placed in classpath is to let the build tool produce a WAR file (e.g. rightclick project, Export > WAR file in Eclipse) and then inspect its contents with a ZIP tool. If the servlet class is missing in /WEB-INF/classes , or if the export causes an error, then the project is badly configured or some IDE/project configuration defaults have been mistakenly reverted (e.g. Project > Build Automatically has been disabled in Eclipse).

    You also need to make sure that the project icon has no red cross indicating a build error. You can find the exact error in Problems view (Window > Show View > Other…). Usually the error message is fine Googlable. In case you have no clue, best is to restart from scratch and do not touch any IDE/project configuration defaults.

    Test the servlet individually without any JSP/HTML page

    Provided that the server runs on localhost:8080 , and that the WAR is successfully deployed on a context path of /contextname (which defaults to the IDE project name, case sensitive!), and the servlet hasn’t failed its initialization (read server logs for any deploy/servlet success/fail messages and the actual context path and servlet mapping), then a servlet with URL pattern of /servlet is available at http://localhost:8080/contextname/servlet .

    You can just enter it straight in browser’s address bar to test it invidivually. If its doGet() is properly overriden and implemented, then you will see its output in browser. Or if you don’t have any doGet() or if it incorrectly calls super.doGet() , then a “HTTP 405: HTTP method GET is not supported by this URL” error will be shown (which is still better than a 404 as a 405 is evidence that the servlet itself is actually found).

    Overriding service() is a bad practice, unless you’re reinventing a MVC framework — which is very unlikely if you’re just starting out with servlets and are clueless as to the problem described in the current question 😉

    Regardless, if the servlet already returns 404 when tested invidivually, then it’s entirely pointless to try with a HTML form instead. Logically, it’s therefore also entirely pointless to include any HTML form in questions about 404 errors from a servlet.

    Use domain-relative URL to reference servlet from HTML

    Once you’ve verified that the servlet works fine when invoked individually, then you can advance to HTML. As to your concrete problem with the HTML form, the value needs to be a valid URL. The same applies to , ,

    Источник

    how to solve Apache Tomcat 404 Page not found error?

    Today I was running Apache Tomcat from Eclipse and while accessing URL http://localhost:8080 found HTTP Status 404 – Not Found error.

    The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    Do you have any of below questions?

    • Tomcat starts but doesn’t display webpage
    • Can’t connect to Tomcat even though it’s running
    • How to Solve Common Tomcat Problems
    • Can’t connect to localhost via browser. Can ping localhost
    • How to open tomcat home page in browser
    • localhost 8080 not working for tomcat

    For all above types of issues,  you are at right place.

    I’ve setup Apache Tomcat by following detailed steps using in-depth tutorial.

    Steps worked perfectly fine but as I didn’t have any projects added to tomcat webapps folder it threw 404 error for me.

    If you also face 404 Page not found error then try following below steps:

    Step-1

    • Go to Eclipse IDE
    • Click on Servers Tab
    • Double click on Tomcat v9.0 Server at localhost

    Tomcat Click on Servers Tab and then double click on Tomcat Server

    Step-2

    • New Apache Tomcat configuration page will open
    • Go to Server Location section
    • Select Use Tomcat installation (takes control of Tomcat installation)

    Apache Tomcat Server Location Change to Fix 404 Error

    Step-3

    • Save configuration
    • Restart Server by right clicking on tomcat server and click Restart
    • Visit http://localhost:8080 again and now you should see working tomcat page

    Localhost 8080 - 404 not found apache tomcat error resolved

    I hope this tutorial works well for you. Happy coding and keep visiting.

    This tutorial works for Apache Tomcat 10.0 too.

    Apache Tomcat 10 running fine on Mac


    Join the Discussion

    If you liked this article, then please share it on social media. Still have any questions about an article, leave us a comment.

    Share:

    I’m an Engineer by profession, Blogger by passion & Founder of Crunchify, LLC, the largest free blogging & technical resource site for beginners. Love SEO, SaaS, #webperf, WordPress, Java. With over 16 millions+ pageviews/month, Crunchify has changed the life of over thousands of individual around the globe teaching Java & Web Tech for FREE.

    Reader Interactions

    This error indicates that the server could not find the desired resource. This resource can be any file such as JSP, HTML, or image resource. Usually, the resource is present, but it is referenced incorrectly. In most cases, you can fix this by correcting the URL. Here are three strategies you can use to look for errors:

    1. Java servlets do not handle URL
    2. Servlet forwarding the resource does not exist
    3. URL is case-sensitive

    1. Java servlets do not handle URL

    Your @Webservlet() may handle for URL/name; however, the URL requested may be URL/this_name (different reference). You can fix this by correcting the reference URL or URL mapping.

    In code, it may look something like this:

    @WebServlet("/name")
    public class Name extends HttpServlet {
    ...
    }
    

    However, your website requested /this_name instead of /name. One way you can correct this is by changing /name to /this_name in your URL mapping.

    2. Servlet forwarding the resource does not exist

    Make sure that the forwarded resource exists. If the resource you are trying to reference is not named correctly, you may also run into this problem. For instance, you are referencing signupForm.jsp, but the name of the resource is signup_Form.jsp. In code it may look something like this:

    String signupForm= "frontend/signupForm.jsp";
    RequestDispatcher dispatcher = request.getRequestDispatcher(signupForm);
    dispatcher.forward(request, response);
    

    You can fix this by correcting the servlet’s path which, in this case, would be to change signupForm.jsp to signup_Form.jsp.

    3. URL is case-sensitive

    If you typed the URL yourself, you might have mistyped it. Tomcat URLs are case-sensitive. For instance, signup is different than signUp. Make sure your URL is case-sensitive.

    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии

    А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка 404 при загрузке файла
  • Ошибка 404 при загрузке страницы