import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Random;
import java.util.Date; import java.util.Random; import javax.servlet.RequestDispatcher; import org.camp.servlet.ResultData;
/** *
@author guest1Day */ public class FortuneTelling extends HttpServlet {
/**
GET
and POST
String luckList [] = {"Daikichi", "Nakakichi", "Kichi", "Hankichi", "Suekokichi", "Bad", "Small", "Half", "Bad", "Bad" , "Danger"};
Random rand = new Random();
//乱数所得
Integer index = rand.nextInt(luckList.length);
out.print ("Votre fortune aujourd'hui" + luckList [index]);
/* TODO output your page here. You may use following sample code. /
out.println("");
out.println("");
out.println("");
out.println("
out.println("");
out.println("");
out.println("Servlet FortuneTelling at " + request.getContextPath() + "
");
out.println("");
out.println("");
ResultData data = new ResultData();
data.setD(new Date());
data.setLuck(luckList[index]);
request.setAttribute("DATA",data);
La partie (résultat) de la ligne ci-dessous sera affichée si le symbole est introuvable en raison d'une erreur. Veuillez noter que cela ne sert à rien même si vous essayez diverses choses.
RequestDispatcher rd =request.getRequestDispatcher(result);
rd.forward(request,response);
}
}
// GET
method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Recommended Posts