我正试图从文本字段输入中获取值
在我的testservlet.java中
out.println("<form id='name' action='' method='post'>");
out.println("<input type="text" name='hostname'>");
out.println("<input type="submit" value="Submit">");
out.println("</form>");
String name = request.getParameter("hostname");
并将其放入cookie中
boolean flag = false;
Cookie[] ck = request.getCookies();
for(Cookie c : ck){
if(c.getName() != null){
out.println(c.getName());
flag = true;
break;
}
}
if(!flag){
Cookie c = new Cookie("name",name);
c.setMaxAge(25);
response.addCookie(c);
out.println("user was add " +c.getName() + ", " + c.getValue());
}
但它不起作用,出了什么问题?