Olá galera tudo bom ?
Vou direto ao assunto, segue esses códigos em Java.
package com.example.model;
import java.util.ArrayList;
public class GameExpert {
public ArrayList getBrands(String jogos) {
ArrayList<String> a = new ArrayList<String>();
if (a.equals("")) {
a.add("Legal você em, mas esse jogo é null, ou seja não existe.");
}
if (a.equals("Metal Gear Solid 4: Guns Of The Patriots")) {
a.add("Melhor jogo de todos os tempos, sem dúvida nenhuma.");
}
if (a.equals("Call Of Duty 4: Modern Warfare")) {
a.add("Melhor jogo de tiro em primeiro pessoa, COD > MOH");
}
if (a.equals("GTA IV")) {
a.add("GTA IV = Único");
}
if (a.equals("Gran Turismo 5 Prologue")) {
a.add("Gran Turismo 5 melhor jogo de corrida, exclusividade By Sony PS3");
}
if (a.equals("Uncharted: Drake's Fortune")) {
a.add("Jogo da nova geração, sensacional, outra exclusivdade By Sony PS3");
}
return a;
}
}
package com.example.web;
import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SelectGames extends HttpServlet {
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Playstation 3: <br> ");
String games = request.getParameter("jogos");
GameExpert be = new GameExpert();
ArrayList result = be.getBrands(games);
out.print("<br> " + result);
}
}
PS: Tem o código HTML pra tudo isso;
É o seguinte quando eu executo isso ele apresenta Playstation 3: e deveria sair o nome do jogo + o comentário q coloquei a respeito dele, mas ele apresenta isso "[]", acho q o retorno do Array q está errado, mas eu coloquei "a.get(0)" e ele dá erro;
Tentei mudar essa linha
ArrayList result = be.getBrands(games);
out.print("<br> " + result);