Hey Guys iam trying to make a simple Java Servlet that returns a JSON. The web.xml is in the WEB-INF directory and i checked already if i typed in the link false or something like that. Here is my ServletClass:
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(name = "BetaAuthServlet", value = "/betaAuthServlet")
public class BetaAuthServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String message = "Test";
out.print(message);
out.flush();
}
}
Here is my 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">
<servlet>
<servlet-name>BetaAuthServlet</servlet-name>
<servlet-class>de.hanimehagen.tridentdevelopment.betaauth.BetaAuthServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BetaAuthServlet</servlet-name>
<url-pattern>/BetaAuthServlet</url-pattern>
</servlet-mapping>
</web-app>
When i lounch the App an go on localhost:8080/betaAuthList i got a 404 error. Iam not realy sure if i need a index.jsp but i think i dont need it. The Tomcat server should work fine. It would be very nice if someone could help me. Greetings Hagen
I found a solve for my problem: I used Tomcat Version 10. After i used Version 9 it works!