nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   Software Development (http://www.nvnews.net/vbulletin/forumdisplay.php?f=53)
-   -   Arrays in JSP's? (http://www.nvnews.net/vbulletin/showthread.php?t=108659)

Tuork 02-22-08 08:24 PM

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!

jcrox 02-22-08 11:12 PM

Re: Arrays in JSP's?
 
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?

Tuork 02-23-08 10:06 PM

Re: Arrays in JSP's?
 
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?

jcrox 02-23-08 10:40 PM

Re: Arrays in JSP's?
 
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.

Tuork 02-24-08 10:09 AM

Re: Arrays in JSP's?
 
Thanks anyway, mate.


All times are GMT -5. The time now is 11:22 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.