You should separate the "getting the length" logic,
and the "display the length" logic.
I think that you should get the length in the servlet,
put it in the response,
and redirect the response to a
JSP file, containing the textfield.
JSP --submit-> Servlet --redirect--> JSP -- and so on -> ....
Do you have to stick to HTML, or can you use JSP instead ?