Eclipse error using Tomcat 9.0 Tomcat server - Error 404

Asked

Viewed 414 times

0

I’m trying to run a web site using Servlet Tomcat9,where the user will enter his salary, and according to the salary range will be made a readjustment on this old salary! The language used is JAVA

I created the Beans and Web Packages ,which were requested by the teacher,I also created the html file! My HTML page is running normal, but at the time of sending the data,:

HTTP Status 404 - Not Found : The origin server Did not find a Current representation for the target Resource or is not willing to disclose that one exists: The origin server Did not find a Current representation for the target Resource or is not willing to disclose that one exists.

And I really don’t know what to do to fix this,I’ve seen tutorials that say to change the location of the server - I did and it hasn’t changed at all. Then I ask for help to solve the error! I am also sending my HTML codes, The Goods code and the WEB!

  1. Create a Servlet that receives the salary of a collaborator and the adjustment according to the following criterion, based on current salary: a. wages up to R $ 280,00 (including): 20% increase b. wages between R$ 280.00 and R$ 700.00: increase of 15% c. wages between R$ 700.00 and R$ 1500.00: 10% increase d. wages of R $ 1500,00 onwards: increase of 5%

CÓDIGO BEANS

package br.com.fiap.com.web;

public class Salario {
	
	private double salario;

	public Salario() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Salario(double salario) {
		super();
		this.salario = salario;
	}

	public double getSalario() {
		return salario;
	}

	public void setSalario(double salario) {
		this.salario = salario;
	}
       
	public double  
	elseSalario (double salario ){
		
		if(salario <= 280.00) {
			salario = salario * 0.20;
		}
		else if(salario > 280.00 && salario < 700.00) {
			salario = salario * 0.15;
		}
		else if(salario > 700.00 && salario < 1500.00) {
			salario = salario * 0.10;
		}
		else if(salario > 1500.00) {
			salario = salario * 0.05;
}
		return salario;	
	 }
	
	public double  
	calculaPorcentagem (double salario ){
		
		if(salario <= 280.00) {
			salario = salario * 0.20;
		}
		else if(salario > 280.00 && salario < 700.00) {
			salario = salario * 0.15;
		}
		else if(salario > 700.00 && salario < 1500.00) {
			salario = salario * 0.10;
		}
		else if(salario > 1500.00) {
			salario = salario * 0.05;
}
		return salario;	
	}
}



CÒDIGO WEB

package br.com.fiap.nac.beans;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.fiap.com.web.Salario;

@WebServlet(urlPatterns="/salario")
public class CalcSalario extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		PrintWriter writer = resp.getWriter();
		
		writer.println("<html><body>");
		writer.println("Seu Salário foi Reajustado");
		
		
		Salario salario = new Salario();
		salario.setSalario(Double.parseDouble(req.getParameter("Salario")));
		writer.println("<p>"+salario.elseSalario(salario.getSalario())+"</p>"); 
		
		
}
		
 }


	
		
		
		
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Salário</title>
</head>
<body>
<h2>Vamos calcular seu novo salário?</h2>
<fieldset>
  <legend>Dados:</legend>
    <form action="recebe" method="get">
    <label for="salario"><b>Salário:</b></label>
    <input type="text" id="idsalario" name="seusalario"
    placeholder="Digite o seu salário"/>
    <button>Enviar</button>
    </form>
</fieldset>

</body>
</html>

  • A guess because I didn’t test the code urlPatterns="/salario" and in html is form action="recebe". The action must send to the URL of Servlet ("/salary"). Since it is sending to a URL that probably does not exist ("receives"), it gives 404 error. And after you fix it: In Herblet you do req.getParameter("Salario"), but the field name in html is name="seusalario", IE, Servlet is trying to get a field name that does not exist in html, so it will also give error. This is what I saw at first glance, as I didn’t test it may be that I have more things to change...

  • hkotsubo then where should I arrange? in the url or in my form action?

  • because if I change the urlPatterns="/salary" to / receives it continues with error ,even if I change the getParameter to your salary

  • 1

    I did a test here, I put urlPatterns = "/recebe" and form action="recebe" and it worked. I created a web project at eclipse from scratch, with the two classes and html and I didn’t have to do anything else. You tried to access the URL directly just to see if it is ok? http://servidor/nomeaplicacao/recebe. Maybe it’s some detail of configuration missing, I don’t know...

  • thanks for the help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.