⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voteedit.jsp

📁 一个JSP代码,有关投票
💻 JSP
字号:
<%@page
    language="java"
    contentType="text/html;charset=GBK"
%>
<%@include file="session.jsp"%>
<%@include file="/config.jsp"%>
<%@include file="/jdbc_database.jsp"%>
<%
String tempstr="";
String sqlstr="";
String title="修改投票项目";
String sqlstr1="";
String sqlstr2="";
int kk=0;
int i=1;
try
{
if(request.getParameter("id")!=null&&request.getParameter("count")!=null)
{
    int count=Integer.valueOf(request.getParameter("count")).intValue();
    String updatebrifstr="";
    String addbrifstr="";
    String updatenumstr="";
    String addnumstr="";

     int type=Integer.parseInt(request.getParameter("type"));
	 int id=Integer.parseInt(request.getParameter("id"));

   sqlstr1="select type from vote where type=1 and id!="+id;
    result=statement.executeQuery(sqlstr1);
    if(result.next())
	{if(type==1){
	   type=0;
       kk=1;}
	}

 sqlstr2="select type from vote where type=2 and id!="+id;
    result=statement.executeQuery(sqlstr2);
    if(result.next())
	{if(type==2){
	   type=0;
       kk=1;}
	}





    for(i=0;i<count;i++)
    {
        updatebrifstr=request.getParameter("brif"+i);
        updatenumstr=request.getParameter("num"+i);
        if(updatebrifstr.length()>0)
        {
            sqlstr="update vote set type='"+type+"',brif='"+updatebrifstr+"',num='"+updatenumstr+"' where id='"+request.getParameter("id")+"' and voteid='"+i+"'";
            statement.executeUpdate(sqlstr);
        }
    }
    for(int j=0;j<2;j++)
    {
        addbrifstr=request.getParameter("brif"+(count+j));
        addnumstr=request.getParameter("num"+(count+j));
        if(addbrifstr.length()>0)
        {
            sqlstr="insert into vote values("+request.getParameter("id")+","+type+","+(i+1)+",'"+addbrifstr+"','"+addnumstr+"')";
            statement.executeUpdate(sqlstr);
            out.print(sqlstr+"<br>");
        }
		if(kk==1){response.sendRedirect("voteadmin.jsp?statestr=10");}
        else
        {
            response.sendRedirect("voteadmin.jsp?statestr=2");
            return;
        }
    }

	
    response.sendRedirect("voteadmin.jsp?statestr=2");
    return;
}
if(request.getParameter("editid")==null)
{
    response.sendRedirect("voteadmin.jsp?statestr=4");
    return;
}
String editid=request.getParameter("editid");
sqlstr="select * from vote where id='"+editid+"' order by voteid";
result=statement.executeQuery(sqlstr);
%>
<html>
<head>
    <META http-equiv="Content-Type" content="text/html; charset=gb2312">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-store">
    <LINK rel="stylesheet" type="text/css" href="../css/style.css">
    <title>修改投票项目</title>
</head>
<body class="mainBody" class="mainBody" onLoad="MM_preloadImages('../images/cancel2.gif','../images/queding2.gif')">

<!--***************************主体表格分界*****************************-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="35">
<tr>
     <td width="25"><img src="../images/space.gif" width="25"></td>
     <td width="55"><img src="../images/title_head.gif" width="55" height="35"></td>
     <td width="100%" background="../images/title_bg.gif" valign="bottom"> <font size="3" face="黑体" color="#6600CC">投票设置</font>
         <font size="2" class="alertColor" face="Arial, Helvetica, sans-serif">──<%=title%></font></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="16">
  <tr>
    <td background="../images/line_top.gif"  height="16">&nbsp;</td>
  </tr>
</table>
<br>
<center>
   <table cellspacing=1 cellpadding=0 border=0 bordercolordark=#FFFFFF width="100%">
                        <tr height=20>
                            <td>
<%
if(result.next())
{
%>
     <table border="1" cellpadding="4" cellspacing="1" style="border-collapse:collapse;border-color:#9DDE8E;" width="93%" bordercolorlight="#808080" bordercolordark="#D4D4D4">
		<form method="post" action="voteedit.jsp" name="form1" >
		  <tr>
			<td width="10%" align="center" nowrap class="boxHead">投票主题</td>
			<td background="../images/leftbg2.gif" colspan=2><input type="text" name="brif0" size=75 value="<%=result.getString("brif")%>"></td>
		  </tr>
		  <tr height=20>
			<td background="../images/leftbg2.gif" colspan=3 align=left><font color="<%=Page_warncolor%>">(投票介绍和各选项文字均不能超过50个汉字)</font></td>
		  </tr>
<%
}
else
{
    response.sendRedirect("voteadmin.jsp?statestr=1");
    return;
}
String selectstr[]=new String[10];
selectstr[result.getInt("type")]="selected";
while(result.next())
{
%>
                                      <tr height="30">
                                        <td align="center" nowrap class="boxHead">选项<%=i%></td>
                                        <td background="../images/leftbg2.gif" width=50>
                                            <input type="text" name="brif<%=i%>" size="60" value="<%=result.getString("brif")%>">
                                        </td>
                                        <td align="center" background="../images/leftbg2.gif">
                                            得票数:<input type="text" name="num<%=i%>" size=6 value="<%=result.getString("num")%>">
                                        </td>
                                      </tr>
<%
    i++;
}
%>
                                      <tr height="30">
                                        <td nowrap class="boxHead" align="center">类型:</td>
                                        <td background="../images/leftbg2.gif" colspan=2>
                                            <select name="type">
                                                <option value=0 <%=selectstr[0]%>>暂停使用</option>
                                                <option value=1 <%=selectstr[1]%>>内网显示</option>
                                                <option value=2 <%=selectstr[2]%>>外网显示</option>
                                               
                                            </select>
                                        </td>
                                      </tr>
                                      <tr height=40>
                                        <td background="../images/leftbg2.gif" colspan=3><font color="<%=Page_warncolor%>">新增选项:</font></td>
                                      </tr>
                                      <tr height="30">
                                        <td nowrap class="boxHead" align="center">选项<%=i%></td>
                                        <td background="../images/leftbg2.gif">
                                            <input type="text" name="brif<%=i%>" size="60">
                                        </td>
                                        <td background="../images/leftbg2.gif" align="center" nowrap>
                                            得票数:<input type="text" name="num<%=i%>" size=6 value=0>
                                        </td>
                                      </tr>
                                      <tr height="30">
                                        <td nowrap class="boxHead" align="center">选项<%=i+1%></td>
                                        <td background="../images/leftbg2.gif">
                                            <input type="text" name="brif<%=i+1%>" size="60">
                                        </td>
                                        <td background="../images/leftbg2.gif" align="center" nowrap>
                                            得票数:<input type="text" name="num<%=i+1%>" size=6 value=0>
                                        </td>
                                      </tr><input type="hidden" name="id" value="<%=editid%>"><input type="hidden" name="count" value="<%=i%>">
                                     <center>
										  
  <tr height=30>
                    <td colspan=3 align="center"><a href="javascript:send()"><input type=image src="/images/queding1.gif" onMouseOver="this.src='../images/queding2.gif'" onMouseOut="this.src='../images/queding1.gif'"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                </tr>
</center> 
                                    </form>                            
                                    </table>
                                    </center>
                          <table width="100%" border="0" cellspacing="0" cellpadding="0" height="16">
						  <tr>
							<td height="16" background="../images/line.gif">&nbsp;</td>
						  </tr>
						</table>
						<BR>
                       
                        
                        <tr height=30 align=center>
                            <td align=center>
                                <a href="voteadmin.jsp">全部投票项目</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="voteaddnew.jsp">新增投票项目</a>
                            </td>
                        </tr>
                    </table>
<!--***************************主体表格分界*****************************-->
<script language="JavaScript">
function send()
{
    for(i=0;i<<%=i+2%>;i++)
    {
        votecon=eval("document.form1.brif"+i+".value");
        if(votecon.indexOf("\'")>=0||votecon.indexOf("\"")>=0||votecon.indexOf("<")>=0||votecon.indexOf(">")>=0)
        {
            //votecon=trim(votecon);
            //document.form1.eval("brif"+i).value=checkstring(votecon);
            alert("输入不能包含 \' \" < > 这些符号!");
            return false;
        }
        if(votecon.length>50)
        {
            alert("投票介绍和各选项文字均不能超过50个汉字!");
            return false;
        }
    }
	 document.form1.submit();
    return true;
}
</script>
</body>
</html>
<%
}
catch(Exception e)
{
    response.sendRedirect("voteadmin.jsp?statestr=3");
    return;
}
finally
{
    try{
        if(result!=null)
        {
            result.close();
            result=null;
        }
        if(statement!=null)
        {
            statement.close();
            statement=null;
        }
        if(con!=null)
        {
            con.close();
            con=null;
        }
    }catch(Exception e){}
}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -