I am trying to load my servlet in the browser and it gives me this error

KIM

This is the error I see when I try to compile my code — am I passing the URL incorectly? I wanted to learn from this sample code to display my servlet in the browser.

HTTP Status 404 - /Lesson41/

type Status report

message /Lesson41/

description The requested resource is not available.

Apache Tomcat/8.0.22

My servlet code is as follows:

 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;

    /**
     * Servlet implementation class Lesson41
     */

    @WebServlet("/Lesson41")
    public class Lesson41 extends HttpServlet {
        private static final long serialVersionUID = 1L;

        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */ 

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String usersName = request.getParameter("YourName");

            String theLang = request.getParameter("Language");

            int firstNum = Integer.parseInt(request.getParameter("Firstnum"));
            int secondNum = Integer.parseInt(request.getParameter("secondnum"));
            int sumONum = firstNum + secondNum;

            response.setContentType("text/html");

            PrintWriter output = response.getWriter();

            output.println("<html><body><h3>Hello " + usersName);

            output.println("</h3><br />" + firstNum + " + " + secondNum);
            output.println(" = " + sumONum + "<br />Speaks " + theLang + "</body></html>");
        }

        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }

    }

This is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>HelloServers</display-name>
  <servlet> 
      <servlet-name>Lesson41</servlet-name>
      <servlet-class>HelloServelets-Lesson41</servlet-class>
      </servlet>

  <servlet-mapping>
          <servlet-name>Lesson41</servlet-name>
          <url-pattern>http://localhost:8080/Lesson41/</url-pattern>
      </servlet-mapping>
</web-app>
AsSiDe

You have to take following steps:

 1. Remove <Servlet> and <servlet-mapping> tags and anything in between them. Since you have used @WebServlet annotation. There is no need to declare those tags in web.XML.
  1. In your form tag replace action attribute to: action="Lesson41"

  2. Don't try to call the Servlet directly through the URL, you are posting some data with your request. First try to load your HTML page and then hit the submit button to call the Servlet's doPost() method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I am trying to install the drivers and the kernel gives me this error:

From Dev

I am trying to build my game in unity but it is giving me an error

From Dev

I am trying to build my game in unity but it is giving me an error

From Dev

when i am trying to call a servlet page from my jsp page using anchor tag it showing an error

From Dev

I am trying to use amazon api code in php but it is giving me error of not supported version following is my code

From Dev

When i am trying to run the xml file, browser show me the message Error loading stylesheet: Failure analysis XSLT stylesheet

From Dev

I am trying to call Web api Post method (i.e.PostMedication)written by me from ajax call ,It gives me error "The resource cannot be found."

From Dev

I'm trying to manipulate a simple props in React but it gives me an error

From Dev

SQL: I am trying to add a foreign key but it give me error

From Dev

I am trying to interact with a servlet on my laptop through an android activity on my phone

From Dev

i am trying to create a simple hibernate application.It gives following error.how to solve that error

From Dev

I am trying to share a project in github using IntelliJ IDEA but i gives a following error

From Dev

I am trying to calculate a percentage in my sql statement which gives a wrong answer

From Dev

How can i load a link in other net browser that i am showing in my web view?

From Dev

Whenever I try flutter run, it gives me the same error and I am not sure what to do

From Dev

I am trying to install new component using npm. But it gives error

From Dev

I am trying to create udp socket and send a string through it. but it gives 10038 error at sendto()

From Dev

Trying to push my app to heroku gives me this error FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'

From Dev

when I am trying to launch my app in my device and I am getting the error as launch option nil in my xcode?

From Dev

Rails Generate Controller gives me load error

From Dev

Rails Generate Controller gives me load error

From Dev

I am currently learning about Android services,all the coding part is good,but the manifest gives me the following error

From Dev

I am trying to load variables in an array

From Dev

I am trying to make a div slide in on load and my previous solution is no longer working?

From Dev

I'm not entirely sure what's wrong with my code, my IDE gives me an error

From Dev

I am getting error while trying to load a activity from adapter class

From Dev

While trying to load data using DSE graphloader I am getting the error - DSE Graph not configured to process queries

From Dev

I am getting an Error when trying to load a map bigger than 4

From Dev

I am getting error while trying to load a activity from adapter class

Related Related

  1. 1

    I am trying to install the drivers and the kernel gives me this error:

  2. 2

    I am trying to build my game in unity but it is giving me an error

  3. 3

    I am trying to build my game in unity but it is giving me an error

  4. 4

    when i am trying to call a servlet page from my jsp page using anchor tag it showing an error

  5. 5

    I am trying to use amazon api code in php but it is giving me error of not supported version following is my code

  6. 6

    When i am trying to run the xml file, browser show me the message Error loading stylesheet: Failure analysis XSLT stylesheet

  7. 7

    I am trying to call Web api Post method (i.e.PostMedication)written by me from ajax call ,It gives me error "The resource cannot be found."

  8. 8

    I'm trying to manipulate a simple props in React but it gives me an error

  9. 9

    SQL: I am trying to add a foreign key but it give me error

  10. 10

    I am trying to interact with a servlet on my laptop through an android activity on my phone

  11. 11

    i am trying to create a simple hibernate application.It gives following error.how to solve that error

  12. 12

    I am trying to share a project in github using IntelliJ IDEA but i gives a following error

  13. 13

    I am trying to calculate a percentage in my sql statement which gives a wrong answer

  14. 14

    How can i load a link in other net browser that i am showing in my web view?

  15. 15

    Whenever I try flutter run, it gives me the same error and I am not sure what to do

  16. 16

    I am trying to install new component using npm. But it gives error

  17. 17

    I am trying to create udp socket and send a string through it. but it gives 10038 error at sendto()

  18. 18

    Trying to push my app to heroku gives me this error FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'

  19. 19

    when I am trying to launch my app in my device and I am getting the error as launch option nil in my xcode?

  20. 20

    Rails Generate Controller gives me load error

  21. 21

    Rails Generate Controller gives me load error

  22. 22

    I am currently learning about Android services,all the coding part is good,but the manifest gives me the following error

  23. 23

    I am trying to load variables in an array

  24. 24

    I am trying to make a div slide in on load and my previous solution is no longer working?

  25. 25

    I'm not entirely sure what's wrong with my code, my IDE gives me an error

  26. 26

    I am getting error while trying to load a activity from adapter class

  27. 27

    While trying to load data using DSE graphloader I am getting the error - DSE Graph not configured to process queries

  28. 28

    I am getting an Error when trying to load a map bigger than 4

  29. 29

    I am getting error while trying to load a activity from adapter class

HotTag

Archive