I have a form to which radio inputs are generated using js code. But when I try to submit the form, the selected value is not being sent to servlet and I am getting null pointer exception.
onMyPage.jsp
<form action="generate" method="post">
<%
for (Monitor mtr : maInfo.getMonitor()) {
out.println("<input style=\"margin-left:20px\" type=\"radio\" name=\"monitor\" value=\""+mtr.getMonitorAbbr()+"\"/>"+mtr.getMonitorAbbr()+"<br>");
}
%>
<input type="submit" value="Submit" onclick="this.disabled=true"/>
</form>
On servlet.java
String variable = (String) request.getAttribute("monitor");
Error message:
java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "javax.servlet.http.HttpServletRequest.getAttribute(String)" is null
request.getAttribute("monitor")userequest.getParameter("monitor").