您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

JSP生成jpeg图片用于投票

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-02 03:00 点击:

首文件index.jsp(SUN企业级应用的首选)如下:

<%--

Author: Tony Wang

E-mail: lucky_tony@163.net

Date: 2001-01-01

如果对程序有什么疑问,可以和我联系, 另外程序如果有什么bug,麻烦指出!!

--%>

<%@ page contentType="text/html;charSet=gb2312"%>
<%
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);
%>
<%!
public String[] getQuestion(String s)
{
String[] strQ = new String[4];
String strTemp = null;
int i;
java.io.Randomaccess(小型网站之最爱)File rf = null;
try {
rf = new java.io.Randomaccess(小型网站之最爱)File(s,"r");
} catch(Exception e)
{
System.out.println(e);
System.exit(0);
}
for(i=0;i<4;i++)
{
try {
strTemp = rf.readLine();
} catch(Exception e) {
strTemp = "None Question";
}
if(strTemp==null)strTemp = "None Question";
strQ[i] = strTemp;
}
return strQ;
}

%>

<%
String s = null;
String[] question = new String[4];

s = request.getRealPath("question.txt");
question = getQuestion(s);
%>


<html>
<head>
<title></title>
<link href="css.css" rel="StyleSheet" type="text/css"></link>
</head>

<body>
<table width="180" border="1" bordercolor="#999999">
<tr>
<td align=center>冰帆调查</td>
</tr>
<form name=frm method=post action=write.jsp(SUN企业级应用的首选)>
<tr>
<td>
<%
String ss = null;
for (int i=0;i<4;i++)
{
ss = "<input type="radio" name="choice" value=" + i+">"+

(char)(´A´+i)+"、"+ question[i]+"<br>";
out.println(ss);
}
%>
</td>
</tr>
<tr>
<td align=center><input type=submit value="我 投 一 票"></td>
</tr>
<tr>
<td align=center><img src="/vote/servlet/VoteImage" width=150

height=100></td>
</tr>
</form>
</table>
</body>
</html>


三、写文件write.jsp(SUN企业级应用的首选)

<%--
Author: Tony Wang
E-mail: lucky_tony@163.net
Date: 2001-01-01
如果对程序有什么疑问,可以和我联系,
另外程序如果有什么bug,麻烦指出!!
--%>
<%!
public int[] getNumber(String s)
{
int[] mCount = new int[4];
String strTemp = null;
int i;
java.io.Randomaccess(小型网站之最爱)File rf = null;
try {
rf = new java.io.Randomaccess(小型网站之最爱)File(s,"r");
} catch(Exception e)
{
System.out.println(e);
System.exit(0);
}
for(i=0;i<4;i++)
{
try {
strTemp = rf.readLine();
} catch(Exception e) {
strTemp = "0";
}
if(strTemp==null)strTemp = "0";
mCount[i] = new Integer(strTemp).intValue();
}
return mCount;
}

public void setNumber(String s,int[] x)
{
try {
java.io.PrintWriter pw = new java.io.PrintWriter(new java.io.

FileOutputStream(s));
for (int i=0;i<4;i++){
pw.println(x[i]+"");
}
pw.close();
} catch(Exception e) {
System.out.println("Write file error:"+e.getMessage());
}
}
%>


<%
String tmp = null;
int choice = -1;
int[] count = new int[4];
tmp = request.getParameter("choice");
if (tmp==null){
} else {
choice = new Integer(tmp).intValue();
}
/////////////
String s = request.getRealPath("count.txt");
if(choice>=0){
count = get

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • JSP与Servlet
      • 自己动手写MiniBBS系列(基本篇)之用户登录
      • JSP取当前日期
      • JDBC 入门(一)
      • 打开一个jsp页面默认查询所有数据,调用action
      • 使用JSP标签库验证用户的输入(2)完
      • WIN98/2000下的jsp服务器
      • 自定义JSP标签(tag)浅议
      • Struts学习傻瓜式入门篇
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1