Ошибка 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

38.3k19 gold badges108 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,0661 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,1401 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,3029 gold badges27 silver badges50 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,21013 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

69.4k35 gold badges181 silver badges252 bronze badges

answered Jul 6, 2022 at 18:04

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

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

2682 silver badges10 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

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.

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

Last Update:2017-05-24
Source: Internet

Author: User

I’m going to make a POC, get an old project, use the war exploded to deploy to the native Tomcat (version 8.5)

When you start Tomcat by IntelliJ idea, you find that the login page of the system is http-status-404 error, and when you open http://localhost:8080 directly in the browser, you can open the Tomcat welcome page, It means Tomcat is up, but it doesn’t load the WebApps directory properly.

Even more strangely, the startup script under Tomcat’s Bin directory can start normally, either by double-clicking Startup.bat or by using Catalina.bat run under the directory’s CMD to start the project normally.

If you have a similar situation of friends, you can pay attention to the two startup mode at the start of the log environment variables, especially catalina_home.

Because the value of this variable is different on my machine when it is started in two ways, Catalina_home is the Tomcat directory where the bin is located when it is started by the bat script in the bin directory;

But when you start with IntelliJ idea, the value of the variable changes to: C:UsersCratical. Intellijidea2017.1systemtomcatunnamed_test-project_3_0_4

Two directories under the Conf folder, the folder inside the name and number of configuration files are the same, through the comparison, found in the Conf directory, Server.xml content There are some differences, note this line

autodeploy= «true» deployonstartup= » False «deployignore=» ^ (?! (manager) | (Tomee) $). * «>

Because in IntelliJ idea, a war format artifact can modify the location of the output directory, the default is the target folder under the current project root directory, if you use IntelliJ directly When idea started Tomcat, the WebApps directory under the Tomcat directory was unable to find the associated deployment folder.

IntelliJ idea is to achieve this goal by generating one of its own catalina_home, modifying the appbase in Server.xml.

Go back to that line of configuration, note that the deployignore property, my web directory name is exactly matched by the above regular expression, so Tomcat is directly ignored when loading, resulting in the 404 error.

The meanings of the various configurations in Tomcat Server.xml, see: http://www.importnew.com/17124.html

Intellij idea + Tomcat resolution for HTTP status 404 error

MichaelPak

0 / 0 / 0

Регистрация: 02.08.2011

Сообщений: 31

1

09.07.2014, 18:04. Показов 16933. Ответов 4

Метки нет (Все метки)


Проблема уже обсуждалась здесь, но никто так и не ответил.

Создаю проект:

Полсе этого сразу же пытаюсь запустить дефолтный index.jsp:

В output следующее:

Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"/Users/michaelpak/tomcat 8/bin/catalina.sh" run [2014-07-09 05:49:26,124] Artifact WebApp:war exploded: Server is not connected. Deploy is not available. 09-Jul-2014 17:49:27.027 INFO [main] org.apache.catalina.core.AprLifecycleListener.init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/michaelpak/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 09-Jul-2014 17:49:27.422 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 09-Jul-2014 17:49:27.442 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-nio-8080"]  java.net.BindException: Address already in use     at sun.nio.ch.Net.bind0(Native Method)     at sun.nio.ch.Net.bind(Net.java:414)     at sun.nio.ch.Net.bind(Net.java:406)     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)     at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:343)     at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:727)     at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:456)     at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:120)     at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     at org.apache.catalina.core.StandardService.initInternal(StandardService.java:567)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:834)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     at org.apache.catalina.startup.Catalina.load(Catalina.java:576)     at org.apache.catalina.startup.Catalina.load(Catalina.java:599)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:483)     at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)   09-Jul-2014 17:49:27.444 SEVERE [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-8080]]  org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8080]]     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)     at org.apache.catalina.core.StandardService.initInternal(StandardService.java:567)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:834)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     at org.apache.catalina.startup.Catalina.load(Catalina.java:576)     at org.apache.catalina.startup.Catalina.load(Catalina.java:599)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:483)     at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484) Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed     at org.apache.catalina.connector.Connector.initInternal(Connector.java:962)     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)     ... 12 more Caused by: java.net.BindException: Address already in use     at sun.nio.ch.Net.bind0(Native Method)     at sun.nio.ch.Net.bind(Net.java:414)     at sun.nio.ch.Net.bind(Net.java:406)     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)     at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:343)     at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:727)     at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:456)     at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:120)     at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)     ... 13 more   09-Jul-2014 17:49:27.444 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 09-Jul-2014 17:49:27.456 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 09-Jul-2014 17:49:27.462 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 904 ms 09-Jul-2014 17:49:27.503 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 09-Jul-2014 17:49:27.503 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.9 09-Jul-2014 17:49:27.511 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 09-Jul-2014 17:49:27.520 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 57 ms Connected to server [2014-07-09 05:49:27,905] Artifact WebApp:war exploded: Artifact is being deployed, please wait... [2014-07-09 05:49:28,383] Artifact WebApp:war exploded: Artifact is deployed successfully [2014-07-09 05:49:28,384] Artifact WebApp:war exploded: Deploy took 478 milliseconds 09-Jul-2014 17:49:37.514 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /Users/michaelpak/tomcat 8/webapps/manager 09-Jul-2014 17:49:37.567 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /Users/michaelpak/tomcat 8/webapps/manager has finished in 52 ms

И браузер автоматически открывает страницу index.jsp, которую не может найти:

И на последок конфигурации:

Как и предыдущий новичок в этом деле, промучился около 4 часов. Подскажите, в чем может быть проблема?

Добавлено через 5 минут
index.jsp:

HTML5
1 2 3 4 5 6 7 8 9 
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html>   <head>     <title></title>   </head>   <body>     </body> </html>

web.xml:

XML
1 2 3 4 5 6 
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1"> </web-app>

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь

0

Эксперт Java

4087 / 3821 / 745

Регистрация: 18.05.2010

Сообщений: 9,331

Записей в блоге: 11

09.07.2014, 20:01

2

Лучший ответ Сообщение было отмечено MichaelPak как решение

Решение

java.net.BindException: Address already in use

Кто-то уже пользуется одним из тех портов, которые вы указали.

Если в командной строке выполнить:
netstat -ano | findstr 8080
То можно узнать PID процесса, который занимает порт и попробовать убить его.

0

0 / 0 / 0

Регистрация: 02.08.2011

Сообщений: 31

09.07.2014, 23:46

 [ТС]

3

Вот такую штуку пишет:

Миниатюры

Intellij Idea + Tomcat = ERROR 404
 

0

Эксперт Java

2390 / 2216 / 564

Регистрация: 28.12.2010

Сообщений: 8,658

10.07.2014, 00:32

4

Лучший ответ Сообщение было отмечено MichaelPak как решение

Решение

MichaelPak, найдите этот процесс в таск манагере (по айди) и убейте.

0

MichaelPak

0 / 0 / 0

Регистрация: 02.08.2011

Сообщений: 31

10.07.2014, 12:45

 [ТС]

5

Убить процесс с именем Java?

Добавлено через 1 час 52 минуты
Поймите, что наш если бы 8080-й порт был занят, то была бы ошибка браузера. А страницу 404 формирует сервер tomcat. Не думаю, что в этом дело.

Добавлено через 22 минуты
Господа, прошу прощения, вы были правы. Убив процесс:

Bash
1 
sudo kill -9 12507

сервер заработал:
http://habrastorage.org/files/… 95e99d.png

0

I’m having a problem with my first Web Application. I use IntelliJ as IDE and Tomcat as Webserver.
Every servlet I’ve tried to acces, throws an 404 Error. Even if I copy some youtube tutorials, which seems to work like a charm.

The button in the form sends me to: http://localhost:8080/IUBHQuiz/login

Can you tell me whats wrong? I am going nuts.

login.java

package com.example.IUBHQuiz;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
@WebServlet("/login")
public class login extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String email = request.getParameter("fmail");
String pass = request.getParameter("fpw");
if(email.equals("j") && pass.equals("j"))
{
RequestDispatcher rs = request.getRequestDispatcher("/main.jsp");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("/index.jsp");
rs.include(request, response);
}
out.close();
}

index.jsp

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>IUBH Quiz</title>
<link href="./resources/css/style.css" rel="stylesheet">
</head>
<body>
<div class="main">
<div class="image-container">
<img src="./resources/images/logo.png" alt="Logo">
</div>
<div class="Login">
<h1>Willkommen beim IUBH-Quiz!</h1>
<form action="login" method="post">
E-Mail:<input type="text" id="fmail" name="fmail"><br><br>
Passwort: <input type="password" id="fpw" name="fpw"><br><br>
<input type="submit" value="Log In" class="button">
</form>
</div>
<div class="Links">
<a href="#">Passwort vergessen</a>
<a href="#">Registrieren</a>
</div>
</div>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>

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

Sheeraz Gul
Jul 25, 2022

  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

  • Fix the Error: Failed to Create the Java Virtual Machine
  • Fix the Missing Server JVM Error in Java
  • Fix the ‘No Java Virtual Machine Was Found’ Error in Eclipse
  • Fix the Error: Failed to Create the Java Virtual Machine
  • Javax.Net.SSL.SSLHandShakeException: Remote Host Closed Connection During Handshake
  • Java.Lang.VerifyError: Bad Type on Operand Stack

Понравилась статья? Поделить с друзьями:
  • Ошибка 404 нет такой страницы wordpress
  • Ошибка 404 нет страницы как добавить
  • Ошибка 404 не открывается не одна страница
  • Ошибка 404 не могу зайти в админку
  • Ошибка 404 на яндекс музыке