当前位置: 技术问答>java相关
谁有servlet的doget()方法的GIF格式传输数据的源码?
来源: 互联网 发布时间:2015-09-28
本文导语: 代码: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.awt.*; public class processImage extends HttpServlet { static final private String CONTENT_TYPE = "image/gif; charset=GBK"; //Initialize global...
代码:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.*;
public class processImage extends HttpServlet {
static final private String CONTENT_TYPE = "image/gif; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
System.out.println("processImage.init() is run");
super.init();
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Processing deGet() Metheod");
response.setContentType(CONTENT_TYPE);
// ServletOutputStream out = response.getOutputStream();
OutputStream out = response.getOutputStream();
Image im = CreateLocalImage();
try {
GIFEncoder ge = new GIFEncoder(im);
ge.write(out);
} catch( Exception e ){
// some error handling code
System.out.println("An exception occur in class processImage.doGet:" + e.getMessage());
}
out.flush();
/**
* out.println("");
* out.println("processImage");
* out.println("");
* out.println("
* out.println("");
**/
}
public Image CreateLocalImage(){
System.out.println("Image.CreateLocalImage() is run.");
Frame imgfrm = new Frame();
imgfrm.addNotify();
Image im = imgfrm.createImage(100, 100);
Graphics g = im.getGraphics();
g.drawString("Hello, How are you?", 10,50);
return im;
}
//Clean up resources
public void destroy() {
System.out.println("processImage.destroy() is run");
super.destroy();
}
}
知道的告诉一下经验也可以,我总是调试不过
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.*;
public class processImage extends HttpServlet {
static final private String CONTENT_TYPE = "image/gif; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
System.out.println("processImage.init() is run");
super.init();
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Processing deGet() Metheod");
response.setContentType(CONTENT_TYPE);
// ServletOutputStream out = response.getOutputStream();
OutputStream out = response.getOutputStream();
Image im = CreateLocalImage();
try {
GIFEncoder ge = new GIFEncoder(im);
ge.write(out);
} catch( Exception e ){
// some error handling code
System.out.println("An exception occur in class processImage.doGet:" + e.getMessage());
}
out.flush();
/**
* out.println("");
* out.println("processImage");
* out.println("");
* out.println("
The servlet has received a GET. This is the reply.
");* out.println("");
**/
}
public Image CreateLocalImage(){
System.out.println("Image.CreateLocalImage() is run.");
Frame imgfrm = new Frame();
imgfrm.addNotify();
Image im = imgfrm.createImage(100, 100);
Graphics g = im.getGraphics();
g.drawString("Hello, How are you?", 10,50);
return im;
}
//Clean up resources
public void destroy() {
System.out.println("processImage.destroy() is run");
super.destroy();
}
}
知道的告诉一下经验也可以,我总是调试不过
|
你生成的gif 有问题,用bufferimage试一下?
|
不可以运行在LINUX下,除非有XWIN。
|
java.lang.NoClassDefFoundError: processImage (wrong name: image/processImage)
看来是你配置的有问题,你用的是tomcat吗??看一下关于tomcat关于servlet的配置的文档吧,好像tomcat的FAQ里面就有
另外保证你的.class文件放的路径没错
看来是你配置的有问题,你用的是tomcat吗??看一下关于tomcat关于servlet的配置的文档吧,好像tomcat的FAQ里面就有
另外保证你的.class文件放的路径没错
|
你的GIFEncoder是哪里来的??
另外,错误是什么?说清楚些
另外,错误是什么?说清楚些