Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在servlet中使用getAttributeNames_Java_Html_Servlets - Fatal编程技术网

Java 在servlet中使用getAttributeNames

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&

我试图从servlet中检索从HTML提交的数据。我使用netbeans并试图获取getAttributes()返回的枚举。 html是

   <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();