Li Wu:
Good study and thinking, honouring teachers save Thanksgiving. Leaf See root three return to one, rivers the same oneness.
Meekness conscience lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and Cherish.
Javaee:7
javase:1.8
jstl:1.2.2
Server:tomcat 8.5
Browser:chrome/firefox
Os:windows7 x64
Ide:myeclipse
Project directory Structure
Xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "> <display-name>day12</ display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file& Gt;index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file> Default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file> default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>verifycodeservlet </servlet-name> <servlet-class>com.jizuiku.servlet.VerifyCodeServlet</servlet-class> </ servlet> <servlet-mapping> <servlet-name>VerifyCodeServlet</servlet-name> <url-pattern>/verifycodeservlet</url-pattern> </servlet-mapping> </web-app>
Servlet Class Code
Package Com.jizuiku.servlet;import Java.awt.color;import Java.awt.font;import java.awt.graphics2d;import Java.awt.image.bufferedimage;import Java.io.fileoutputstream;import Java.io.ioexception;import java.util.Random; Import Javax.imageio.imageio;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * * * @author blog Park-to the most bitter * Version V2017.11.30 */public class Verifycodeservlet extends HttpServlet {@Overrideprotected void doget ( HttpServletRequest req, httpservletresponse Response) throws servletexception, IOException {//this code needs to be optimized, The code that generates the picture can be integrated into a tool class int width = 100;int height = 50;int ImageType = bufferedimage.type_int_bgr; BufferedImage myimage = new BufferedImage (width, height, imageType); graphics2d pen = (graphics2d) myimage.getgraphics ();p en.setcolor (color.white);p en.fillrect (0, 0, 100, 50); Font font = new Font ("microsoft JAS black", 2);p en.setfont (font);p en.setcolor (color.blue);pEn.drawstring (integer.tostring (new Random (). nextint (100)), 20, 35);//focus! Response.getoutputstream (); imageio.write (myimage, "JPEG", response.getoutputstream ());}}
index.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String BasePath = Request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/";%>& lt;! DOCTYPE HTML public "-//w3c//dtd HTML 4.01 transitional//en" >Browser View index.jsp page
Click on the hyperlink to change a look
Learning resources: itcast and Itheima video library. If you have public resources, can share to me, with your resources to learn also Can.
Blog post is to watch the video, into thinking Written. It's good that the teacher speaks Well. Blog bad, is to give the most bitter not serious.
HttpServletResponse Getoutputstream Click on the hyperlink to change the picture (requires the JS function of the Mate)