Get checkbox values from JSP Page












0















I'm trying to get all the values from a list of selected checkboxs in a JSP Page, to a Java Class.
That's My JSP Page:



    <table border="1" cellpadding="5" cellspacing="1" style="width: 877px; ">
<tr>
<th>Code</th>
<th>Name</th>
<th>Price</th>
<th>Select</th>
<th>Edit</th>
<th>Delete</th>
<th>Show</th>
</tr>
<c:forEach items="${productList}" var="product" >
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.price}</td>
<td>
<input type="checkbox" name="ProductItem" value="${product.code}">
<c:url value="ShowProductList" var="url">
<c:param name="ProductItemP" value="${product.code}"/>
</c:url>
</td>
<td>
<a href="editProduct?code=${product.code}">Edit</a>
</td>
<td>
<a href="deleteProduct?code=${product.code}">Delete</a>
</td>
<td>
<a href="ShowProduct?code=${product.code}">Show</a>
</td>
</tr>
</c:forEach>
</table>


<a href="${url}">Show Items</a>


As you can see there is a Table with a list of items with a check box in each line. At the end of the table there is button "Show Items" that triggers the user's request.
That's the servlet class that perform the request:



    @WebServlet(urlPatterns = { "/ShowProductList" })
public class ShowProductList extends HttpServlet {
private static final long serialVersionUID = 1L;

public ShowProductList() {
super();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Connection conn = MyUtils.getStoredConnection(request);

String paramValues = request.getParameterValues("ProductItemP");
System.out.println(paramValues.length);
response.sendRedirect(request.getContextPath() + "/productList");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}


When an user select two or more checkbox and click on the button "Show item" I can have only the last product code with the checkbox clicked and not all the codes with the box selected. If I Try request.getParameterValues("ProductItem"); I have a null value. I'd prefer to not have code in the JSP Page (if it is possible.)
Can someone help me find a solution ?
Thanks for your patience.



`










share|improve this question

























  • Why you want to get all products codes when you choose specific product?

    – user7294900
    Nov 25 '18 at 10:34











  • Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

    – Roberto
    Nov 25 '18 at 12:01











  • How did you filled productList? Same way get the values in the servlet.

    – Evgeni Enchev
    Nov 26 '18 at 10:46











  • @EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

    – Roberto
    Nov 27 '18 at 9:22
















0















I'm trying to get all the values from a list of selected checkboxs in a JSP Page, to a Java Class.
That's My JSP Page:



    <table border="1" cellpadding="5" cellspacing="1" style="width: 877px; ">
<tr>
<th>Code</th>
<th>Name</th>
<th>Price</th>
<th>Select</th>
<th>Edit</th>
<th>Delete</th>
<th>Show</th>
</tr>
<c:forEach items="${productList}" var="product" >
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.price}</td>
<td>
<input type="checkbox" name="ProductItem" value="${product.code}">
<c:url value="ShowProductList" var="url">
<c:param name="ProductItemP" value="${product.code}"/>
</c:url>
</td>
<td>
<a href="editProduct?code=${product.code}">Edit</a>
</td>
<td>
<a href="deleteProduct?code=${product.code}">Delete</a>
</td>
<td>
<a href="ShowProduct?code=${product.code}">Show</a>
</td>
</tr>
</c:forEach>
</table>


<a href="${url}">Show Items</a>


As you can see there is a Table with a list of items with a check box in each line. At the end of the table there is button "Show Items" that triggers the user's request.
That's the servlet class that perform the request:



    @WebServlet(urlPatterns = { "/ShowProductList" })
public class ShowProductList extends HttpServlet {
private static final long serialVersionUID = 1L;

public ShowProductList() {
super();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Connection conn = MyUtils.getStoredConnection(request);

String paramValues = request.getParameterValues("ProductItemP");
System.out.println(paramValues.length);
response.sendRedirect(request.getContextPath() + "/productList");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}


When an user select two or more checkbox and click on the button "Show item" I can have only the last product code with the checkbox clicked and not all the codes with the box selected. If I Try request.getParameterValues("ProductItem"); I have a null value. I'd prefer to not have code in the JSP Page (if it is possible.)
Can someone help me find a solution ?
Thanks for your patience.



`










share|improve this question

























  • Why you want to get all products codes when you choose specific product?

    – user7294900
    Nov 25 '18 at 10:34











  • Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

    – Roberto
    Nov 25 '18 at 12:01











  • How did you filled productList? Same way get the values in the servlet.

    – Evgeni Enchev
    Nov 26 '18 at 10:46











  • @EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

    – Roberto
    Nov 27 '18 at 9:22














0












0








0








I'm trying to get all the values from a list of selected checkboxs in a JSP Page, to a Java Class.
That's My JSP Page:



    <table border="1" cellpadding="5" cellspacing="1" style="width: 877px; ">
<tr>
<th>Code</th>
<th>Name</th>
<th>Price</th>
<th>Select</th>
<th>Edit</th>
<th>Delete</th>
<th>Show</th>
</tr>
<c:forEach items="${productList}" var="product" >
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.price}</td>
<td>
<input type="checkbox" name="ProductItem" value="${product.code}">
<c:url value="ShowProductList" var="url">
<c:param name="ProductItemP" value="${product.code}"/>
</c:url>
</td>
<td>
<a href="editProduct?code=${product.code}">Edit</a>
</td>
<td>
<a href="deleteProduct?code=${product.code}">Delete</a>
</td>
<td>
<a href="ShowProduct?code=${product.code}">Show</a>
</td>
</tr>
</c:forEach>
</table>


<a href="${url}">Show Items</a>


As you can see there is a Table with a list of items with a check box in each line. At the end of the table there is button "Show Items" that triggers the user's request.
That's the servlet class that perform the request:



    @WebServlet(urlPatterns = { "/ShowProductList" })
public class ShowProductList extends HttpServlet {
private static final long serialVersionUID = 1L;

public ShowProductList() {
super();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Connection conn = MyUtils.getStoredConnection(request);

String paramValues = request.getParameterValues("ProductItemP");
System.out.println(paramValues.length);
response.sendRedirect(request.getContextPath() + "/productList");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}


When an user select two or more checkbox and click on the button "Show item" I can have only the last product code with the checkbox clicked and not all the codes with the box selected. If I Try request.getParameterValues("ProductItem"); I have a null value. I'd prefer to not have code in the JSP Page (if it is possible.)
Can someone help me find a solution ?
Thanks for your patience.



`










share|improve this question
















I'm trying to get all the values from a list of selected checkboxs in a JSP Page, to a Java Class.
That's My JSP Page:



    <table border="1" cellpadding="5" cellspacing="1" style="width: 877px; ">
<tr>
<th>Code</th>
<th>Name</th>
<th>Price</th>
<th>Select</th>
<th>Edit</th>
<th>Delete</th>
<th>Show</th>
</tr>
<c:forEach items="${productList}" var="product" >
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.price}</td>
<td>
<input type="checkbox" name="ProductItem" value="${product.code}">
<c:url value="ShowProductList" var="url">
<c:param name="ProductItemP" value="${product.code}"/>
</c:url>
</td>
<td>
<a href="editProduct?code=${product.code}">Edit</a>
</td>
<td>
<a href="deleteProduct?code=${product.code}">Delete</a>
</td>
<td>
<a href="ShowProduct?code=${product.code}">Show</a>
</td>
</tr>
</c:forEach>
</table>


<a href="${url}">Show Items</a>


As you can see there is a Table with a list of items with a check box in each line. At the end of the table there is button "Show Items" that triggers the user's request.
That's the servlet class that perform the request:



    @WebServlet(urlPatterns = { "/ShowProductList" })
public class ShowProductList extends HttpServlet {
private static final long serialVersionUID = 1L;

public ShowProductList() {
super();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Connection conn = MyUtils.getStoredConnection(request);

String paramValues = request.getParameterValues("ProductItemP");
System.out.println(paramValues.length);
response.sendRedirect(request.getContextPath() + "/productList");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}


When an user select two or more checkbox and click on the button "Show item" I can have only the last product code with the checkbox clicked and not all the codes with the box selected. If I Try request.getParameterValues("ProductItem"); I have a null value. I'd prefer to not have code in the JSP Page (if it is possible.)
Can someone help me find a solution ?
Thanks for your patience.



`







java jsp java-ee checkbox checkboxlist






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 16:37







Roberto

















asked Nov 25 '18 at 10:30









RobertoRoberto

87




87













  • Why you want to get all products codes when you choose specific product?

    – user7294900
    Nov 25 '18 at 10:34











  • Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

    – Roberto
    Nov 25 '18 at 12:01











  • How did you filled productList? Same way get the values in the servlet.

    – Evgeni Enchev
    Nov 26 '18 at 10:46











  • @EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

    – Roberto
    Nov 27 '18 at 9:22



















  • Why you want to get all products codes when you choose specific product?

    – user7294900
    Nov 25 '18 at 10:34











  • Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

    – Roberto
    Nov 25 '18 at 12:01











  • How did you filled productList? Same way get the values in the servlet.

    – Evgeni Enchev
    Nov 26 '18 at 10:46











  • @EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

    – Roberto
    Nov 27 '18 at 9:22

















Why you want to get all products codes when you choose specific product?

– user7294900
Nov 25 '18 at 10:34





Why you want to get all products codes when you choose specific product?

– user7294900
Nov 25 '18 at 10:34













Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

– Roberto
Nov 25 '18 at 12:01





Hi, Because I would like to have all the selected product code to query them. I have another servlet that select a single code with the code: String code = (String) request.getParameter("code"); it works and give me a single code. But when a try to collect all the parameter of the name="ProductItem" it give to me null value. i've tried also with request.getParameterValues but nothin. thanks

– Roberto
Nov 25 '18 at 12:01













How did you filled productList? Same way get the values in the servlet.

– Evgeni Enchev
Nov 26 '18 at 10:46





How did you filled productList? Same way get the values in the servlet.

– Evgeni Enchev
Nov 26 '18 at 10:46













@EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

– Roberto
Nov 27 '18 at 9:22





@EvgeniEnchev productList is filled by a class that performs a query with no code value as filter. In my ShowProductlist page I would like to query only the selected items (by checkbox) from the productList page. To perform that I need to pass to the query a list of codes. Thanks

– Roberto
Nov 27 '18 at 9:22












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466601%2fget-checkbox-values-from-jsp-page%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466601%2fget-checkbox-values-from-jsp-page%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin