-1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="/details">
        First name: <input type="text" name="fname"><br> 
        Last name: <input type="text" name="lname"><br>
        <br> <input type="submit" value="Submit">
    </form>
</body>
</html>
@WebServlet("/details")  
public class ShowDetails extends HttpServlet {
    
    /**
     * 
     */
    private static final long serialVersionUID = 7384650098624517113L;

    public void service(HttpServletRequest request, HttpServletResponse response) {
        String fName = request.getParameter("fname");
        String lName = request.getParameter("lname");
        
        System.out.println(fName + " " + lName );
        
    }

}

after clicking submit enter image description here

it must print the value on console enter image description here

HTML page enter image description here

imxitiz
  • 3,920
  • 3
  • 9
  • 33
akash pal
  • 3
  • 2

1 Answers1

0

Change <form action="/details"> to <form action="/DemoServlet/details">.

Since the servlet path is relative to /DemoServlet (you can set this in web.xml), the ShowDetails servlet will be at localhost:2222/DemoServlet/details and not just localhost:2222/details.