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" , "Achtung"};
Random rand = new Random();
//乱数所得
Integer index = rand.nextInt(luckList.length);
out.print ("Ihr Vermögen heute" + Glücksliste [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);
Der (Ergebnis-) Teil der folgenden Zeile wird angezeigt, wenn das Symbol aufgrund eines Fehlers nicht gefunden werden kann. Bitte weisen Sie darauf hin, dass es auch dann nutzlos ist, wenn Sie verschiedene Dinge ausprobieren.
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