The original author of this article is Tony Wang, which covers the reading and writing of files and the automatic generation of JPG images. Using Jsp+servlet technology, the JSP calls the servlet to generate pictures.
Second, the first document INDEX.JSP as follows:
<%--
Author:tony Wang
E-mail:lucky_tony@163.net
Date:2001-01-01
If you have any questions about the program, you can contact me, another program if there are any bugs, trouble points out!!
<%--
Author:tony Wang
E-mail:lucky_tony@163.net
Date:2001-01-01
If you have any questions about the program, you can contact me,
Another program if there are any bugs, trouble point out!!
--%>
<%!
Public int[] GetNumber (String s)
{
int[] Mcount = new Int[4];
String strtemp = null;
int i;
Java.io.RandomAccessFile RF = NULL;
try {
RF = new Java.io.RandomAccessFile (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.
<%
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 = GetNumber (s);
count[choice]++;
Setnumber (S,count);
}
Response.sendredirect ("index.jsp");
%>
Four, the servlet original code: Voteimage.java:
/*
Author:tony Wang
E-mail:lucky_tony@163.net
Date:2001-01-01
If you have any questions about the program, you can contact me,
Another program if there are any bugs, trouble point out!!
*/
Import java.io.*;
Import java.util.*;
Import com.sun.image.codec.jpeg.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.awt.*;
Import java.awt.geom.*;
Import java.awt.image.*;
public class Voteimage extends HttpServlet
{
Private String strfile = null;
Private Color Color[]={color.red,color.black,color.orange,
Color.green};
private int baseang = 30;
public void doget (HttpServletRequest request,httpservletresponse
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.