Home > Back-end >  For urgent urgent: centos7 its - tomcat 1.8-9, verification code can't display text, only the b
For urgent urgent: centos7 its - tomcat 1.8-9, verification code can't display text, only the b

Time:09-28

 question background: 
(1) using the centos7 own font, unable to display text, the installation Times New Roman to centos7 and jre/fonts also cannot display text
(2) the tomcat catalina. Sh configured in the awt, where the environment has installed a graphical interface, background doesn't configure the awt,
(3) don't display character, also do not report any error

To paraphrase a verification code generation tool online, under Windows display properly:

[code=Java] import Java. The awt. Color;
Import the Java. The awt. The Font;
Import the Java. The awt. Graphics;
Import the Java. The awt. Image. BufferedImage;
import java.util.Random;
/* *
* verification code generation tool
* @ author HXL
*
*/
Public class CaptchaUtil {
Private BufferedImage image;//image
Private String STR.//captcha
Private static char code []="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789". ToCharArray ();

Public static final String SESSION_CODE_NAME="code";

Private CaptchaUtil () {
init();//initialization properties
}

/*
* get RandomNumUtil instance
*/

Public static CaptchaUtil Instance () {
Return new CaptchaUtil ();
}

/*
* get captcha images
*/
Public BufferedImage getImage () {
Return this. The image;
}

/*
* obtain image authentication code
*/
Public String get String () {
Return this. The STR;
}

Private void init () {
//in memory to create image
Int width=85, height=20;
BufferedImage image=new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB);
//get the graphics context
Graphics g=image. GetGraphics ();
//to generate random class
Random random=new Random();
//set the background color in
G.s etColor (getRandColor (200, 250));
G.f illRect (0, 0, width, height);
//set the font
G.s etFont (new Font (" Times new Roman ", the Font. PLAIN, 18));
//random interference lines 155, make the image of the authentication code is not easy to be detected from other programs
G.s etColor (getRandColor (160, 200));
for (int i=0; i <155; I++) {
Int x=random. NextInt (width);
Int y=random. NextInt (height);
Int xl=random. NextInt (12);
Int yl=random. NextInt (12);
G.d rawLine (x, y, x + xl, y + yl);
}
//take random authentication code (4 digits)
String sRand="";
for (int i=0; i <4. I++) {
String rand=String. The valueOf (code [random. NextInt (code. Length)]);
SRand +=rand.
//to display the authentication code in the image
G.s etColor (new Color (20 + the random nextInt (110), 20 + random. NextInt (110), 20 + random. NextInt (110)));
//function call out the color of the same, may be because the seeds too close, so can directly generate
G.d rawString (rand, 13 * I + 6, 16);
}
//assignment captcha
Enclosing the STR=sRand;

//image effect
G.d ispose ();
//ByteArrayInputStream input=null;
//ByteArrayOutputStream output=new ByteArrayOutputStream ();
//try {
//ImageOutputStream imageOut=ImageIO. CreateImageOutputStream (output);
//ImageIO. Write (image, "JPEG", imageOut);
//imageOut. Close ();
//input=new ByteArrayInputStream (output. The toByteArray ());
//} the catch (Exception e) {
//System. Out. Println (" captcha images the error: "+ e. oString ());
//}
//this. Image=input
This. Image=image; Assignment image/* */
}

/*

* for a given range of random color*/
Fc private Color getRandColor (int, int BC) {
Random random=new Random();
If (fc & gt; 255)
Fc=255;
If (BC & gt; 255)
BC=255;
Int r=fc + random. NextInt (BC - fc);
Int g=fc + random. NextInt (BC - fc);
Int b=fc + random. NextInt (BC - fc);
Return the new Color (r, g, b);
}
}
[/code]
  • Related