Java 在servlet中使用getAttributeNames
我试图从servlet中检索从HTML提交的数据。我使用netbeans并试图获取getAttributes()返回的枚举。 html是Java 在servlet中使用getAttributeNames,java,html,servlets,Java,Html,Servlets,我试图从servlet中检索从HTML提交的数据。我使用netbeans并试图获取getAttributes()返回的枚举。 html是 <html> <body> <center> <form name="Form1" action="http://localhost:8080/DemoWeb/TwoParServlet"> <B>Color:</B&
<html>
<body>
<center>
<form name="Form1" action="http://localhost:8080/DemoWeb/TwoParServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br>
<br>
<B>Country:</B>
<select name="country" size="1">
<option value="India">India</option>
<option value="Srilanka">Srilanka</option>
<option value="Chinae">China</option>
</select>
<br>
<br>
<input type=submit value="Submit">
</form>
</center>
</body>
</html>
可能出了什么问题?您应该使用
getParameterNames()
而不是getAttributeNames
Enumeration parameterNames = request.getParameterNames();
有关了解属性和参数之间差异的更多信息,请参阅。您只需检查
名称的大小,它将为零。
因此,这意味着从request.getAttributeNames()
没有返回任何内容
使用request.getParameterNames()
代替您必须查找的request.getAttributeNames()
。参数和属性之间有很大区别。阅读和
java.util.NoSuchElementException
java.util.HashMap$HashIterator.nextEntry(HashMap.java:929)
java.util.HashMap$KeyIterator.next(HashMap.java:960)
java.util.Collections$2.nextElement(Collections.java:3665)
p1.TwoParServlet.doGet(TwoParServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
Enumeration parameterNames = request.getParameterNames();