webwork---vote

webwork实现投票系统;

1.页面部分vote.html
递交和取消按钮用的两js:
js 代码
  1. <!---->
  2. function checkform(src){
  3. var vote=document.getElementsByName("vote");
  4. var i=0;
  5. for( i=0;i
  6. if(vote[i].checked)
  7. {
  8. var src="http://***.com/vote1/vote?vote="+vote[i].value;
  9. }
  10. }
  11. window.open(src,null,"height=160,width=550,status=yes,toolbar=no,menubar=no,location=no");
  12. }
  13. <!---->
  14. function cancelForm()
  15. {
  16. var vote=document.getElementsByName("vote");
  17. vote[4].checked=true;
  18. }

2:创建servlet:Vote.java
webwork通过request.getParameter("vote")获取页面数据;
因为数据不多所以用xml文件存储;通过XMLManager.ReadXML(path)读到Hashtable中;再利用hashtable.get("a")方法取值.进行处理;通过hashtable.put("a",vale)存入hashtable;
HttpSession session=request.getSession();
session.setAttribute("ht",hashtable);将hashtable传给结果页面;
最后:response.sendRedirect("display.jsp");
3:结果页面:display.jsp
<%@page contentType="text/html; charset=gbk"%>
<%@page import="java.util.Hashtable"%>
<%@page import="java.lang.Math"%>



<%
Hashtable ht = (Hashtable) session.getAttribute("ht");
int a1 = Integer.parseInt((String) ht.get("a"));
int b1 = Integer.parseInt((String) ht.get("b"));
int c1 = Integer.parseInt((String) ht.get("c"));
int d1 = Integer.parseInt((String) ht.get("d"));
int e1 = Integer.parseInt((String) ht.get("e"));
int total = a1 + b1 + c1 + d1+e1;

float a = a1;
float b = b1;
float c = c1;
float d = d1;
float e = e1;
%>

你可能感兴趣的:(C++,c,jsp,servlet,Webwork)