Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

servlet faggotry

Name: Anonymous 2008-04-06 12:46

I'm having some problems with servlets.
i'm writing a cookie that contains a car model and a vector containg html links to all other car models made by that manufacturer.
A lot of these models have a manufacturer in common, so i'm using if statements to determine the manufacturer. Everything reads in okay, but i cant get it to actually initialise the right manufactuer name to my 'make' variable.

Here's what i'm doing in my doGet:
Cookie cookies[] = request.getCookies();  // get cookies
String modelList = new String(cookies[ 0 ].getName()); //vector
String model = new String(cookies[ 0 ].getValue()); //the model
String make = ""; //the make(manufacturer)
String[] arr = {"Ford","Toyota","Citroen","Mazda"};
if((model.equalsIgnoreCase("Fiesta")) || (model.equalsIgnoreCase("Focus")) || (model.equalsIgnoreCase("Mondeo")) || (model.equalsIgnoreCase("Mustang")))
                {
                    make += arr[0];
                }
if((model.equalsIgnoreCase("Celica")) || (model.equalsIgnoreCase("Auris")) || (model.equalsIgnoreCase("Yaris")) || (model.equalsIgnoreCase("Prius")))
                {
                    make += arr[1];
                }
if((model.equalsIgnoreCase("C2")) || (model.equalsIgnoreCase("C3")) ||
(model.equalsIgnoreCase("C4")) || (model.equalsIgnoreCase("C5")))
                {
                    make += arr[2];
                }  
else{
                    make += arr[3];
                }

unfortunetly, it always results in the use of my else case...
If print out model, it shows up fine!

Can the might of  /prog/ show me where i'm fucking up?

Name: Anonymous 2009-08-03 10:32

>>1
You intended for the if/else if statements to be mutually exclusive, but that's not what the code says. You need to change the 2nd and 3[sup]rd[sup] if statements into else if statements.

The way it's currently written, the Citroen and Mazda sections will be evaluated independently of the Ford and Toyota sections. So, for example, a cookie value of "Fiesta" will produce a make of "Ford Fiesta Mazda", which is obviously wrong.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List