java - Values not passing from TextBox to Servlet File -


I am filling the user with simple HTML forms with the name and age value & amp; By pressing the submit button it goes into the next servlet file.

My HTML code

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; TODO is a title & lt; / Title & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Meta name = "viewport" content = "width = device-width" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form action = "display" method = "post" & gt; Name & lt; Input type = "text" value = "name" & gt; & Lt; Br> & Lt; / Br & gt; Age & lt; Input type = "article" value = "age" & gt; & Lt; Br> & Lt; / Br & gt; & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt;  

Servlet coding

  package pack; Import java.io.IOException; Import java.io.printWriter; Import javax.servlet.ServletException; Import javax.servlet.http.httpServlet; Import javax.servlet.http.HttpServletRequest; Import javax.servlet.http.HttpServletResponse; Public class performance HttpServlet {@Override protected void doPost (HttpServletRequest request, HttpServletResponse response), ServletException throws IOException {response.setContentType ( "text / html; charset = UTF-8"); PrintWriter out = response.getWriter (); String n = request.getParameter ("name"); String c = request.getParameter ("age"); Out.println ("& lt ;; DOCTYPE html & gt;"); Out.println ("& lt; html>"); Out.println ("top> gt;"); Out.println ("& lt; Title & gt; Servlet Display "); Out.println ("& lt; / head>"); Out.println ("k & lt; body & gt;"); //out.println("tlt;h1>Servlet Display "+ request.getContextPath () +" & lt; / h1 & gt; ";); Out.println ("I" + n + "and my age is" + C); Out.println ("& lt; / body & gt;"); Out.println ("& lt; / html>"); I should be in the form of output:  

I (some names entered in the text box) and age (some age has been entered in the text box).

But the output is:

I am empty and my age is zero.

The values ​​are not exempt from the servlet file from the text box. Can someone suggest what is wrong with the code ... ??

In your HTML, the name attribute, such as:

  & lt; Input type = "text" name = "name" & gt; By the value  attribute  

value is also present, but it is used to set an initial value inside the text box.


Comments