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 bad", "Half bad", "Bad", "Bad" , "Danger"};
Random rand = new Random();
//乱数所得
Integer index = rand.nextInt(luckList.length);
out.print ("Your fortune today" + 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);
The (result) part of the line below will be displayed if the symbol cannot be found due to an error. Please point out that it is useless even if you try various things.
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