QueryString未在Servlet中读取-NullPointer异常



我有一个简单的例子,在单击按钮时调用带有查询参数的servlet。问题是,在servlet中,当我尝试读取查询参数时,我得到了null。

这是我的jsp代码片段。

<form action="http://localhost:8080/ChartsApp/apps/CreateXMLServlet?r=0.7180008697323501&fc=03&fc=04&fc=05">
    <input type="submit" title="Submit"/>
</form>

这是我在doPost 中的servlet代码片段

System.out.println(request.getQueryString());
String[] selectedCodes = (String[]) request.getParameterValues("fc");
if (selectedCodes != null) {
    for (int i = 0; i < selectedCodes.length; i++) {
        System.out.println("fc[" + i + "] = " + selectedCodes[i]);
    }
}

第一个sout是打印null,我在后面的行中得到了nullpointer异常。我做错了什么?

在form标记中添加"post"方法以访问请求参数。

<form method="post" action="http://localhost:8080/ChartsApp/apps/CreateXMLServlet?r=0.7180008697323501&fc=03&fc=04&fc=05">
<input type="submit" title="Submit"/>

最新更新