View Full Version : Arrays in JSP's?
Working on a project for Uni and I have a sheitload of fields I need to pass into a webBean.
I want to use arrays for repeated similar items rather than individual strings (for example: Location1 address, location2 addresss, etc.).
Anyone know how I can do this?
All I know so far is how to send an individual parameter via navigation rules.
Thanks!
lets say you have a form in your JSP with fields with these names:
add1
add2
add3
you fill in the data, click the submit button....
in your servlet:
private webBean bean;
create an array and populate it with the form fields
String[] adds = {request.getParameter("add1"), request.getParameter("add2"), request.getParameter("add3")};
instantiate a new bean and pass the array to the beans constructor
bean = new webBean(adds);
in your webBean constructor:
public webBean(String[] adds) {
setAddress1(adds[0]);
setAddress2(adds[1]);
setAddress3(adds[2]);
}
Is that about what you're trying to do?
Hmm... that all makes sense to me... sort of, except I'm not sure where 'request' comes from. Is it automatically instanciated by the bean?
I recall using it from when I used regular servlets, but the examples I've seen with JSP (particularly the one given to me at uni) don't use it.
The current architecture I'm supposed to use does not involve a servlet in between the web bean and the .jsp.
Any other ideas?
The only other way I can think of would be using a combination of a JSP declaration and JSP expressions. Sorry, I'm not sure how you'd go about doing that though... I was taught that was the "wrong" way to use Java Server Pages.... hopefully someone else here can help you.
vBulletin® v3.7.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.