关于jsp在线投票系统代码的信息
admin 发布:2022-12-19 11:32 97
今天给各位分享jsp在线投票系统代码的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、怎么用jsp实现一个简单的投票系统?
- 2、在线投票系统 用jsp做的 希望有详细的步骤过程、源代码、图片 万分感谢啦
- 3、JAVA语言中用于投票器的代码如何写
- 4、jsp投票系统
- 5、用jsp做网上投票系统 代码
怎么用jsp实现一个简单的投票系统?
要简单的,就:
搞几个选项,然后提交数据,在得到提交数据时,把数据存入一个.txt文件(反正是简单,也不必用数据库了,直接用IO输入输出流,将投票结果保存在文本文件中),写几个数字(有几个选项就写几个数字,并用","等标准符号隔开),查看投票结果,读出文本中的一串数字,并用split()分隔取值。
在线投票系统 用jsp做的 希望有详细的步骤过程、源代码、图片 万分感谢啦
你这是个小项目,做起来也不难,就是费时间,你要是悬赏分给力的话,可以坐坐,我现在花时间做了,啥都没有,不值!
JAVA语言中用于投票器的代码如何写
把投票的信息放在 ServletContext对象 中。也就是 JSP 内置对象中的application对象。因为投票信息是所有用户都要看的信息,所以要把他放在 ServletContext对象 中。这样只要是 应用一加载就会创建 ServletContext对象 直到应用销毁,也就是服务器关闭时,ServletContext对象 才销毁。这样就使得所有用户公用一个对象存储信息。具体的实现那要根据你自己的需求,具体设计。
public class CServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int n = 0;ServletContext application = getServletContext();Integer num = (Integer) application.getAttribute("num");if (num != null) {n = num;}application.setAttribute("num", ++n);response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();out.println("你是第" + n + "个访问者");}}
上面是个类似的例子。你可以参考一下。package servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;这是需要导入的包
jsp投票系统
方法一 在 appliction 中藏一个值,可以 系统年月日作为键,值为计数器,每次投票去查看下当天日期的键下的值是否到达50 ,没有到达计数器+1,进行投票,到达了则不执行投票.
方法二 在 appliction 中藏一个值,可以 固定键,值为计数器,每次投票去查看下当天日期的键下的值是否到达50 ,没有到达计数器+1,进行投票,到达了则不执行投票. 每天0:00 将值设置为0
用jsp做网上投票系统 代码
我之前做过类似的投票小项目,在这里把源码发给你。你自己好好的参考一下。--------------------------package com.tv.bean;public class TVBean {
private String tvName;
private int tvCount;
public String getTvName() {
return tvName;
}
public void setTvName(String tvName) {
this.tvName = tvName;
}
public int getTvCount() {
return tvCount;
}
public void setTvCount(int tvCount) {
this.tvCount = tvCount;
}
}------------------------------package com.tv.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;import com.tv.bean.TVBean;
public class DBUtil {
private Connection con;
private PreparedStatement ps = null;
private ResultSet rs;
public void getCon(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=TV","sa","");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeCon(){
try {
if(rs !=null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ArrayList getAll(){
ArrayList al = new ArrayList();
this.getCon();
String sql = "select * from TVInfo order by tvCount desc";
try {
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
TVBean tb = new TVBean();
tb.setTvName(rs.getString(1));
tb.setTvCount(rs.getInt(2));
al.add(tb);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeCon();
}
return al;
}
public boolean updateByName(String name){
this.getCon();
String sql = "update TVInfo set tvCount=tvCount+1 where tvName='"+name+"'";
try {
ps = con.prepareStatement(sql);
int i = ps.executeUpdate();
if(i 0) return true;
else return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
this.closeCon();
}
}
}
---------------------------------------package com.tv.servlet;import java.io.IOException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import com.tv.dao.DBUtil;public class VoteServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
DBUtil dao = new DBUtil();
String [] name = request.getParameterValues("tvs");
int num = name.length;
for(int i =0; i num; i++){
if(dao.updateByName(name[i])){
request.setAttribute("to", "投票成功!");
ArrayList al = dao.getAll();
HttpSession session = request.getSession();
session.setAttribute("al", al);
request.getRequestDispatcher("success.jsp").forward(request, response);
}else{
request.setAttribute("to", "投票失败!请重新再试!");
}
}
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
-----------------------------------%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
%@taglib prefix="c" uri=" "%html
head
title电视投票/title
/head body
center
form action="vote" method="post"
table border="1" align="center"
tr align="center"
td
h2
选择您最喜欢的电视剧并投上一票
/h2
/td
/tr
tr
td
input type="checkbox" name="tvs" value="咏春" /
咏春
/td
/tr
tr
td
input type="checkbox" name="tvs" value="金婚" /
金婚
/td
/tr
tr
td
input type="checkbox" name="tvs" value="士兵突击" /
士兵突击
/td
/tr
tr
td
input type="checkbox" name="tvs" value="少年张三丰" /
少年张三丰
/td
/tr
tr
td align="center"
input type="submit" value=" 提交 " /
input type="reset" value=" 重置 " /
/td
/tr
/table
/form
/center
/body
/html
-------------------------------------第一段代码为JavaBean;第二段代码为数据库连接类;第三段代码为Servlet控制类;第四段代码为JSP显示页面。希望能够解决你的问题!
jsp在线投票系统代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、jsp在线投票系统代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:小京东代码修改(京东代码规范)
- 下一篇:网页代码投票(html投票代码)
相关推荐
- 05-04vb.net代码入门(vb·net)[20240504更新]
- 05-04文字框代码怎么写(html文字框代码)[20240504更新]
- 05-04qq音乐主页源代码(最新音乐代码)[20240504更新]
- 05-04卡盟资源代码(卡盟控制端全套系统源码)[20240504更新]
- 05-04java多线程代码(java 多线程)[20240504更新]
- 05-04css颜色渐变代码(css颜色渐变代码大全)[20240504更新]
- 05-04页面随鼠标滚轮上下滚动代码(鼠标上下滚动变成左右滚动)[20240504更新]
- 05-04php网站代码(php网站程序)[20240504更新]
- 05-04公众号分享接口代码怎么写入(公众号接口开发教程源码+工具)[20240504更新]
- 05-04网贷代码是什么情况(网贷内部码)[20240504更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接