我是网络开发的初学者。我想将数据发送到servlet,但是我得到了一个NullPointerException。
例如,nickname = admin的值,我可以看到它。当我按下按钮发布到servlet时,我无法传递数据,所有数据都为空。我不明白为什么。我已将另一个(jsp + servlet)的数据加载到我发布的数据中。
<form name="admin_view_user" action="${pageContext.request.contextPath}/admin/users/user/activate" method="POST">
<div id="leftcolumn">
<div>
<img src="${pageContext.request.contextPath}/images/imageholder_detailspage.jpg" alt="" width="220" height="220" class="previewimg" />
</div>
<c:choose>
<c:when test="${active =='1'}">
<h2>Ok</h2>
<br />
</c:when>
<c:otherwise>
<h2>Post</h2>
<div>
<input class="commitbutton" type="submit" alt="buttonActivete" name="buttonActivete" id="buttonActivete" value="Activet" />
</div>
<br />
</c:otherwise>
</c:choose>
</div>
<div id="rightcolumn">
<table class="table">
<tr>
<td width="10%" class="td_attributes">Nickname</td>
<td name="nickname" id="nickname" class="text longfield" value="${nickname}">
<c:out value="${nickname}"/>
</td>
</tr>
</table>
</div>
<div class="clear"> </div>
</form>
</div>
@WebServlet(name = "AdminActivate", urlPatterns = {"/admin/users/user/activate"})
public class AdminActivate extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext servletContext = getServletContext();
try (PrintWriter out = response.getWriter()) {
ViewUserAdminActivet controller = new ViewUserAdminActivet();
Map<String, String[]> parameterMap = request.getParameterMap();
String nickname = parameterMap.get("nickname")[0];
System.out.println(nickname + "________________________________");
// controller.execute(servletContext, parameterMap, request, response);
}
}
在这一行中,我得到了异常Map<String, String[]> parameterMap = request.getParameterMap();