tags:

views:

742

answers:

2

I found this post that shows how to pass multiple check box selections to another JSP page, but it's not working for me. When I try to get the selected values I get:

checked boxes: [Ljava.lang.String;@3f3fbd

Here are my two pages (be gentle, this is my first attempt at JSP!)

createSHAREfile.jsp basically runs a query to find all the terms that have not been processed and show each term with a check box next to it:

<title>Create SHARE Files</title>
</head>
<body>
<jsp:include page="../menu/header.jsp" flush="false" />
<form name='SelectSHARETerms' method='post' action="SHAREProcessing.jsp">
<fieldset><legend>Select Terms to Process for SHARE</legend>
<table align='left'>
<%
String termDetail = "", currDate = "";
currentDateTime datetime = new currentDateTime();
datetime.setCurrDate();
currDate = datetime.getCurrDate();
java.sql.Date todayDate = java.sql.Date.valueOf(currDate);
Terms terms = new Terms();
ArrayList<Terms.termsTable> termsObjList = new ArrayList<Terms.termsTable>();
terms.setTermsSql("Select * from Terms where TermDate <= '" + currDate + "' AND VoucherProcessDate Is Null");
boolean indicator = terms.setListOfTerms();
if (indicator == true)
{
int size = terms.getListSize();
termsObjList = terms.getTermsList();
for (int i=0; i<size; ++i)
{
Terms.termsTable eachTerm = (Terms.termsTable)termsObjList.get(i);
java.sql.Date termDate = eachTerm.TermDate;
%>          
<tr><td><input TYPE=checkbox name=SelectedTermDate id='SelectedTermDate<%= i %>' VALUE="<%= i %>"><%=termDate %></td></tr>
<%
}
}
%>
<tr><td align='center'><input type='submit' value='Submit'></input></td></tr>
</table>
</fieldset>
</form>
</body>
</html>

When the submit button is pressed I call SHAREProcessing.jsp. Right now all i'm trying to do on this page is show which termdates the user has selected so I can use them as parameters to a Java Class that will create the files for the selected terms:

<title>SHARE Processing</title>
</head>
<body>
<jsp:include page="../menu/header.jsp" flush="false" />
<table width='50%' align='center' border='1'>
<% String[] SelectedValues = request.getParameterValues("SelectedTermDate");
System.out.println("checked boxes: " + SelectedValues);
%>
</body>
</html>

Here's where I'm trying to use the code shown in the other post but it's not working :(

Thanks for any help! Leslie

+2  A: 

You're trying to print the whole string array with System.out.println, and so you get that. It's probably working fine.

Try this:

System.out.println("checked boxes:");
for (int i = 0; i < SelectedValues.length; ++i)
  System.out.println("  " + SelectedValues[i]);

Also, I beg you: in your spare time, find out about a modern web framework (there are zillions for Java) and strive to escape from the painful world of coding Java inside JSP files.

Pointy
Zillions of which at highest five are okay to look at first (JSF, Struts2, Spring MVC, Stripes and Wicket). Don't scare him ;)
BalusC
I'm a huge Stripes fan but I didn't want to proselytize.
Pointy
@BalusC - it's "her" LOL@ Pointy - great thanks that helps....i will look at web framework, but I'm not the big web programmer here, just a peon! This does do exactly what I asked for (prints the 0, 1, 2), but what I really need to do is get the date value that is in that Parameter has to pass that into another query...
Leslie
@Leslie: oh!! I'm extremely sorry that I didn't pay attention to the maiden name you used as nickname. Your new avatar indeed clarifies a lot :)
BalusC
Well you're just setting the "value" attribute of each checkbox to "i", not the date.
Pointy
So I would need to make the value attribute the termDate instead? Why yes! that's exactly what I need to do! Thanks!
Leslie
@BalusC - no worries! Happens all the time (usually on sites that don't have my picture though!)
Leslie
A: 

You're just facing the default value of Object#toString().

Either just loop over it and print each item, or use Arrays#toString(). Here's an SSCCE:

package com.stackoverflow.q2426380;

import java.util.Arrays;

public class Test {

    public static void main(String... args) {
        String[] array = {"foo", "bar" , "waa"};
        System.out.println(array); // [Ljava.lang.String;@addbf1

        String arrayAsString = Arrays.toString(array);
        System.out.println(arrayAsString); // [foo, bar, waa]
    }

}

That said, this problem has actually nothing to do with JSP. It's just a view technology. The problem is rather in the basic Java code --which you wrote at the wrong place, in a JSP file instead of a Java class. I strongly agree with the comments that writing raw Java code in JSP files is a bad practice. Start learning Servlets.

BalusC