1

The server is Glassfish

Error 404 Page not found or you are not connected to a network

Web page Code

<html>
<head>
    <title>Wow</title>        
</head>
<body>
    <form  name ="wow" method="post" action="ThatWas">
        Name : <input type="text" name="name">                      
        <input type="submit" value="That">                        
    </form>        
</body>
</html>

Code for Servlet is

public class ThatWas extends HttpServlet {    
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
    String name = request.getParameter("name");         
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ThatWas</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println(" That was good "+ name + request.getContextPath());
        out.println("</body>");
        out.println("</html>");
    }
}

When servlet is run

Result is

That was good + FilePath

When Web page button is clicked

Result is

You are not connected to a network

the result should be That was good + name + File Path

four systems
  • 23
  • 1
  • 8

1 Answers1

0

You have mentioned the method as "post" in the form, but your method in servlet is not doPost. I think that's the error. The method name should be doPost. Also, you have to map the action with servlet class in web.xml.

ZygD
  • 22,092
  • 39
  • 79
  • 102