1

If I run my web project, in the first call I get the right Parameter (request.getParamter(userid)), but if I do more then one call, the request.getParamter Method always returns null.

I don't know why, and I have tried many things.

Thank you for your help.

in jsp I have this:

function addPersonToDatabase(userID){

var check = 0;
for (var zaehler = 0; zaehler < (document.getElementsByName("notinProject[]").length);   
 zaehler++) {

if (document.getElementsByName("notinProject[]")[zaehler].checked) {

location.href='<%=request.getContextPath()%>/administration/persons
action=addfrompersons&comingfrom=' + location.href + '&username=' + userID; 
        check++;
         }      
}


<form name='setcheckbox' id='setcheckbox' action='PersonControllerServlet' method='post' >

<input type="checkbox" name="notinProject[]" value="" onclick='javascript:addPersonToDatabase("
<%=lobjPerson.userName%)'><br> </td>

in servlet I have this:

String lstrUserName=request.getParameter("username");
mhatch
  • 4,441
  • 6
  • 36
  • 62
java java
  • 405
  • 1
  • 11
  • 25
  • Some parameters are good, others are failed. What's the problem? – Roman C Jun 03 '13 at 08:58
  • if i set one checkbox in the frontend, i call in the jsp file the onclick javascript method... it works well, but if i do this a second, i have a null poniter exception on this: String lstrUserName=request.getParameter("username") in my servlet .... ; – java java Jun 03 '13 at 09:41
  • It could be something wrong with the code. – Roman C Jun 03 '13 at 09:43
  • for me its difficult to find the failure ... because in the first call in goes well, but if i do many calls the request.getparamter is null in my servlet. ... – java java Jun 03 '13 at 09:48
  • may be the second time it doesn't have a value? – Roman C Jun 03 '13 at 09:51
  • ok, but do i have to set a value in the input of the checkbox, because by me it is "" : -->
    – java java Jun 03 '13 at 10:32
  • then you have to send it and receive in other way. – Roman C Jun 03 '13 at 10:36
  • yes i send it to the servlet in the url like here:if (document.getElementsByName("notinProject[]")[zaehler].checked) { location.href='<%=request.getContextPath()%>/administration/persons action=addfrompersons&comingfrom=' + location.href + '&username=' + userID; check++; } } – java java Jun 03 '13 at 10:52
  • but it's the same way you do it and servlet doesn't put a value to the url. – Roman C Jun 03 '13 at 11:04

1 Answers1

0

try:

onclick='javascript:addPersonToDatabase("<%=lobjPerson.userName%>")'>
alberto-bottarini
  • 1,213
  • 9
  • 21