import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This Servlet represents and prints a random deal in a Poker game.
*
* @author Sofoklis Stouraitis
*
*/
public class PokerServlet extends HttpServlet {
/*
* A String with all available cards (52 total).
*/
private String[] cards = { "Α Καρό", "Α Κούπα", "Α Σπαθί", "Α Μπαστούνι",
"2 Καρό", "2 Κούπα", "2 Σπαθί", "2 Μπαστούνι", "3 Καρό", "3 Κούπα",
"3 Σπαθί", "3 Μπαστούνι", "4 Καρό", "4 Κούπα", "4 Σπαθί",
"4 Μπαστούνι", "5 Καρό", "5 Κούπα", "5 Σπαθί", "5 Μπαστούνι",
"6 Καρό", "6 Κούπα", "6 Σπαθί", "6 Μπαστούνι", "7 Καρό", "7 Κούπα",
"7 Σπαθί", "7 Μπαστούνι", "8 Καρό", "8 Κούπα", "8 Σπαθί",
"8 Μπαστούνι", "9 Καρό", "9 Κούπα", "9 Σπαθί", "9 Μπαστούνι",
"10 Καρό", "10 Κούπα", "10 Σπαθί", "10 Μπαστούνι", "J Καρό",
"J Κούπα", "J Σπαθί", "J Μπαστούνι", "Q Καρό", "Q Κούπα",
"Q Σπαθί", "Q Μπαστούνι", "K Καρό", "K Κούπα", "K Σπαθί",
"K Μπαστούνι" };
/**
* Handles HTTP GET requests.
*
* @param request
* the request object
* @param response
* the response object
*
* @throws IOException
* if an input or output error is detected when the servlet
* handles the GET request
* @throws ServletException
* if the request for the GET could not be handled
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html; charset=ISO-8859-7");
PrintWriter out = new PrintWriter(response.getWriter(), true);
try {
int card1 = 0;
int card2 = 0;
int card3 = 0;
int card4 = 0;
int card5 = 0;
while ((card1 == card2) || (card1 == card3) || (card1 == card4)
|| (card1 == card5) || (card2 == card3) || (card2 == card4)
|| (card2 == card5) || (card3 == card4) || (card3 == card5)
|| (card4 == card5)) {
card1 = (int) (Math.random() * 52);
card2 = (int) (Math.random() * 52);
card3 = (int) (Math.random() * 52);
card4 = (int) (Math.random() * 52);
card5 = (int) (Math.random() * 52);
}
out.println("<html>");
out.println("<head>");
out.println(" <title>PokerServlet</title>");
out.println(" <meta http-equiv='Content-Type' content='text/html; charset=windows-1253'>");
out.println("</head>");
out.println(" <bodybgcolor='#FFFF99'>");
out.println(" <h1>PokerServlet is running...</h1><br>");
out.println("<b>Έχετε τα παρακάτω φύλλα:</b><br>");
out.println("<hr>");
out.println("1ο φύλλο: <b>" + cards[card1] + "</b><br>");
out.println("2ο φύλλο: <b>" + cards[card2] + "</b><br>");
out.println("3ο φύλλο: <b>" + cards[card3] + "</b><br>");
out.println("4ο φύλλο: <b>" + cards[card4] + "</b><br>");
out.println("5ο φύλλο: <b>" + cards[card5] + "</b><br>");
out.println("<hr>");
out.println("</body>");
out.println("</html>");
} catch (Exception ex) {
out.println("Exception: " + ex.getMessage());
out.println(" </body>");
out.println("</html>");
}
}
}// End of class
|