我找的Servlet生成的随机数图片为什么编译不了如何应用????急???

zyb1235 2004-05-05 09:32:17
servlet

package jzb2b.common;

/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2004-2-19
* Time: 10:43:06
* To change this template use File | Settings | File Templates.
*/
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class image extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{

// 在内存中创建图象
int width=51, height=17;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

// 设定背景色
g.setColor(Color.white);
g.fillRect(0, 0, width, height);

//画边框
g.setColor(Color.black);
g.drawRect(0,0,width-1,height-1);

// 取随机产生的认证码(4位数字)
String rand = new Integer((new Random()).nextInt(9999)).toString();
switch(rand.length())
{
case 1: rand = "000"+rand; break;
case 2: rand = "00"+rand; break;
case 3: rand = "0"+rand; break;
default: rand = rand.substring(0,4); break;
}

// 将认证码存入SESSION
HttpSession session = request.getSession(true);
session.setAttribute("rand",rand);

// 将认证码显示到图象中
g.setColor(Color.black);
g.setFont(new Font("Verdana",Font.BOLD,13));
g.drawString(rand,8,13);

// 随机产生88个干扰点,使图象中的认证码不易被其它程序探测到
Random random = new Random();
for (int i=0;i<88;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
g.drawLine(x,y,x,y);
}

// 图象生效
g.dispose();

// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
}
}


错误是


image.java:15: package javax.servlet does not exist
import javax.servlet.*;
^
image.java:16: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
image.java:18: cannot resolve symbol
symbol : class HttpServlet
location: class jzb2b.common.image
public class image extends HttpServlet{
^
image.java:20: cannot resolve symbol
symbol : class HttpServletRequest
location: class jzb2b.common.image
public void doGet(HttpServletRequest request,HttpServletResponse response)
^
image.java:20: cannot resolve symbol
symbol : class HttpServletResponse
location: class jzb2b.common.image
public void doGet(HttpServletRequest request,HttpServletResponse response)
^
image.java:21: cannot resolve symbol
symbol : class ServletException
location: class jzb2b.common.image
throws ServletException,IOException{
^
image.java:50: cannot resolve symbol
symbol : class HttpSession
location: class jzb2b.common.image
HttpSession session = request.getSession(true);
^
7 errors

如何应用,
...全文
79 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
umbrella1984 2004-05-05
import javax.servlet.*;
import javax.servlet.http.*;
  • 打赏
  • 举报
回复
viano 2004-05-05
image.java:15: package javax.servlet does not exist


没有包! javax.servlet

你在 tomcat5 下面找到 这个 包 然后打包到你的 jdk 下面

或者 你的 服务器lib 下面!
  • 打赏
  • 举报
回复
zyb1235 2004-05-05
错在那
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
加入

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-05-05 09:32
社区公告
暂无公告