服务器上的一张图片 在这个图片上写上XX 字后 从新生成一张图片! 大家有没有这样的代码?谢谢
解决方案 »
- 多线程间通信问题,求解
- 内部类访问控制问题
- TimerTask中scheduleAtFixedRate的使用问题
- 将swing程序通过applet嵌入至网页中
- 正则表达式的问题
- 请教:用sdk1.5+eclipce 3.2+myeclipce 5.0+tomcat 5.5或近似工具进行环境配置
- 把web application打包war的时候,有什么办法让jbuilder不用重新编译没有修改过的jsp文件?(
- 文件操作,高手快来!!!在线等!!!
- 用JDBC连接MYSQL的问题
- 体验JDO(Java Data Object,使用Sun得JDO RI )
- 一道考试题(急)
- 小弟初学,求救:一个线程中加套接字的空指针异常,帮帮我啊
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;public class ChkImgGenerate extends HttpServlet { /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream();
String imgid = request.getParameter("imgid");
response.setContentType("image/jpeg");
out.write(getImgs(imgid));
out.flush();
}
private byte[] getImgs(String imgid){
String query = "select img from chk_img where id='"+imgid+"'";
Blob blob = null;
byte[] bytes = null;
//String description = "";
/*Random rnd = new Random();
for(int i=0; i<ids.length; i++){
int tmp = rnd.nextInt(total);
ids[i] = "0123456789".substring(tmp,tmp+1);
}*/
try{
/*Context initCtx = new InitialContext();
DataSource db = (DataSource) initCtx
.lookup("java:comp/env/jdbc/mysql");
Connection conn = db.getConnection();*/
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test",
"root",
"");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
//ResultSetMetaData md = rs.getMetaData();
while(rs.next()){
blob = rs.getBlob(1);
}
bytes = blob.getBytes(1,(int)(blob.length()));
conn.close();
}catch(Exception e){
e.printStackTrace();
}
return bytes;
}}