哪里的问题呢
package com.imooc.web.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class CheckImgServlet */ @WebServlet("/CheckImgServlet") public class CheckImgServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int width = 120; int height= 30; //步骤一:在内存中生成图片 BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); //步骤二:设置背景 等 操作图片 //获得画笔对象 Graphics graphics = bufferedImage.getGraphics(); //设置背景色 graphics.setColor(Color.PINK); //填充 (坐标,坐标) graphics.fillRect(0, 0, width, height); //绘制边框: graphics.setColor(Color.BLUE); graphics.drawRect(0, 0, width-1, height-1); //将内存中图片输出到浏览器 //第一个参数 内存中的图片,格式化名称, 因为要响应到浏览器上 ImageIO.write(bufferedImage, "jpg", response.getOutputStream()); //步骤三:生成随机四个祖母或数字,写入到图片中 graphics.setColor(Color.BLACK); //(字体,字样式,字号) graphics.setFont(new Font("黑体",Font.BOLD,18)); //随机产生 String words = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); int x=10; for(int i=0;i<4;i++) { int idx = random.nextInt(words.length()); //获得指定位置的字符 并拿到字符 char ch = words.charAt(idx); graphics.drawString(String.valueOf(ch), x, 20); x+=30; } //步骤四:将内存中的图片进行输出 } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
4
收起
正在回答
2回答
同学你好,在同学的回复中看到已经查询出结果,如:
另外The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.这只是提示信息,是提示驱动程序自动注册,不需要手动加载驱动程序类,可以忽略。问一下同学是使用如下加载驱动的吗?
这里可以使用Class.forName("com.mysql.jdbc.Driver");来代替DriverManager.registerDriver(new Driver());加载驱动。
祝:学习愉快~
2. 从网页搭建入门JavaWeb
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星