資源簡介
jsp界面弄的一個很簡單的抽獎項目,可供大家參考參考

代碼片段和文件信息
package?servlet;
import?java.io.IOException;
import?java.util.Random;
import?javax.servlet.RequestDispatcher;
import?javax.servlet.ServletException;
import?javax.servlet.http.HttpServlet;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
public?class?ResultServlet?extends?HttpServlet?{
/**
?*?Constructor?of?the?object.
?*/
public?ResultServlet()?{
super();
}
/**
?*?Destruction?of?the?servlet.?
?*/
public?void?destroy()?{
super.destroy();?//?Just?puts?“destroy“?string?in?log
//?Put?your?code?here
}
/**
?*?The?doGet?method?of?the?servlet.?
?*
?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?get.
?*?
?*?@param?request?the?request?send?by?the?client?to?the?server
?*?@param?response?the?response?send?by?the?server?to?the?client
?*?@throws?ServletException?if?an?error?occurred
?*?@throws?IOException?if?an?error?occurred
?*/
public?void?doGet(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
doPost(requestresponse);
}
/**
?*?The?doPost?method?of?the?servlet.?
?*
?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?post.
?*?
?*?@param?request?the?request?send?by?the?client?to?the?server
?*?@param?response?the?response?send?by?the?server?to?the?client
?*?@throws?ServletException?if?an?error?occurred
?*?@throws?IOException?if?an?error?occurred
?*/
public?void?doPost(HttpServletRequest?request?HttpServletResponse?response)
throws?ServletException?IOException?{
request.setCharacterEncoding(“utf-8“);
String?path?=?“/result.jsp“;//?轉發到的頁面
RequestDispatcher?rd?=?request.getRequestDispatcher(path);//?實現轉發功能
String[]?a={“沒有中獎,謝謝光顧!““沒有中獎,謝謝光顧!““沒有中獎,謝謝光顧!““恭喜你中獎了,詳情請登錄***網站了解““沒有中獎,謝謝光顧!““恭喜你中了特等獎了,詳情請登錄***網站了解““恭喜你中了大獎了,詳情請登錄***網站了解““謝謝光顧““沒有中獎,謝謝光顧!““沒有中獎,謝謝光顧!“};
String?aa=getRandomString(a);
request.setAttribute(“result“?aa);
//request.setAttribute(“result“?“success“);//?調用request的屬性函數
//request.setAttribute(“reson“?“注冊成功!“);//?調用request的屬性函數
rd.forward(request?response);
return;
//System.out.println?(getRandomString(a));
}
public?static?String?getRandomString(String[]?str){?????
Random?rand=new?Random(System.currentTimeMillis());???
return?str[rand.nextInt(10)];
}
/**
?*?Initialization?of?the?servlet.?
?*
?*?@throws?ServletException?if?an?error?occurs
?*/
public?void?init()?throws?ServletException?{
//?Put?your?code?here
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1223??2010-03-08?16:27??Tests\.project
?????文件???????2755??2010-03-08?19:38??Tests\src\servlet\ResultServlet.java
?????文件???????2212??2010-03-08?19:38??Tests\WebRoot\WEB-INF\classes\servlet\ResultServlet.class
?????文件????????662??2010-03-08?16:48??Tests\WebRoot\WEB-INF\web.xm
?????文件?????????39??2010-03-08?14:45??Tests\WebRoot\me
?????文件???????1730??2010-03-08?17:12??Tests\WebRoot\index.jsp
?????文件??????22856??2010-03-08?15:19??Tests\WebRoot\image\1.jpg
?????文件??????14949??2010-03-08?15:18??Tests\WebRoot\image\3.jpg
?????文件??????17200??2010-03-08?17:23??Tests\WebRoot\image\4.jpg
?????文件???????1353??2010-03-08?18:06??Tests\WebRoot\result.jsp
?????文件????????288??2010-03-08?14:45??Tests\.myme
?????文件????????362??2010-03-08?15:18??Tests\.classpath
?????目錄??????????0??2010-03-08?19:34??Tests\WebRoot\WEB-INF\classes\servlet
?????目錄??????????0??2010-03-08?14:45??Tests\WebRoot\WEB-INF\lib
?????目錄??????????0??2010-03-08?14:45??Tests\WebRoot\WEB-INF\classes
?????目錄??????????0??2010-03-08?16:48??Tests\src\servlet
?????目錄??????????0??2010-03-08?14:45??Tests\WebRoot\WEB-INF
?????目錄??????????0??2010-03-08?14:45??Tests\WebRoot\me
?????目錄??????????0??2010-03-08?15:18??Tests\WebRoot\image
?????目錄??????????0??2010-03-08?14:45??Tests\src
?????目錄??????????0??2010-03-08?14:45??Tests\WebRoot
?????目錄??????????0??2010-03-08?14:45??Tests\.myeclipse
?????目錄??????????0??2010-03-08?14:45??Tests
-----------?---------??----------?-----??----
????????????????65629????????????????????23
- 上一篇:android wifi 熱點模式使用
- 下一篇:java 網上在線報名系統
評論
共有 條評論