html+jsp Java Bean程序实现投票系统的部署并运行

toupiao.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>投票</title>
</head>
<body>
<form action="toupiao.jsp" method="post">
请选择一个你最喜欢的奶制品品牌!<br>
蒙牛:<input type="radio" value="1" name="actress"></input><br>
伊利:<input type="radio" value="2" name="actress"></input><br>
古城:<input type="radio" value="3" name="actress"></input><br>
<input type="submit" value="投票"></input>
</form>
</body>
</html>
toupiao.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="pp" class="bean.TouPiao" scope="application"></jsp:useBean>
<jsp:setProperty property="*" name="pp"/>
<%pp.count(); %>
蒙牛:<jsp:getProperty property="n1" name="pp"/><br>
伊利:<jsp:getProperty property="n2" name="pp"/><br>
古城:<jsp:getProperty property="n3" name="pp"/><br>
</body>s
</html>
toupiao.java
package bean;

public class TouPiao {
int actress,n1=0,n2=0,n3=0;
public TouPiao()
{}
public void setActress(int n)
{actress=n;}
public void count()
{ switch(actress)
{
case 1:n1++;break;
case 2:n2++;break;
case 3:n3++;break;
}
}
public int getN1()
{return n1;}
public int getN2()
{return n2;}
public int getN3()
{return n3;}
}
0

Leave a Reply

Your email address will not be published.