当前位置: 技术问答>java相关
再问中文问题,linux下的中文问题,谁能帮我解决:200分
来源: 互联网 发布时间:2015-08-30
本文导语: 文件如下,为什么中文字它不出来? import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.awt.*; import java.awt.image.*; import com.sun.image.codec.jpeg.*; import ...
文件如下,为什么中文字它不出来?
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.text.*;
public class Drawzz extends HttpServlet {
public void drawX(Graphics g,int x,int y)
{g.drawLine(x,y,x,y+2);}
public void drawY(Graphics g,int x,int y)
{g.drawLine(x,y,x+2,y);}
private String getStr(String str){
try{
String temp_p=str;
byte []temp_t=temp_p.getBytes( "8859_1 ");
String temp=new String(temp_t, "gb2312 ");
return temp;
}
catch(Exception ex){
System.err.println( "sq.executeUpdate: "+ex.getMessage());
return null;
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
int jj=0;
String[] s1=new String[100];
double[] s2=new double [100];
double maxs2=0;
response.setContentType( "image/jpeg;charset=8859_1 ");
ServletOutputStream out = response.getOutputStream();
int X=640;//X宽度
int Y=480;//Y宽度
int X_1=30;
int Y_1=30;
BufferedImage image = new BufferedImage(X,Y, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Graphics2D g2d= (Graphics2D)g;
g2d.setBackground(Color.blue);
//底色
g2d.setColor(Color.white);
g2d.fillRect(0,0,image.getWidth(),image.getHeight());
//JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
//encoder.encode(image);
//坐标
g.setColor(Color.black);
g.setFont(new Font( "Helvetica ",Font.PLAIN,12));
g.drawLine(X_1,Y_1,X_1,Y-Y_1);g.drawLine(X_1,Y-Y_1,X-X_1,Y-Y_1);
//Y坐标
//X坐标
int X0=(int)(500/(jj+1));
int x1=30;
int y1=450;
int x2;int y2;
g.drawString( getStr("中文字怎么还不出来呀 "),300,100);
g.drawString( "中文字怎么还不出来呀 ",300,100);
g.drawString( "thisis a bmp ",300,200);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
}
}
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.text.*;
public class Drawzz extends HttpServlet {
public void drawX(Graphics g,int x,int y)
{g.drawLine(x,y,x,y+2);}
public void drawY(Graphics g,int x,int y)
{g.drawLine(x,y,x+2,y);}
private String getStr(String str){
try{
String temp_p=str;
byte []temp_t=temp_p.getBytes( "8859_1 ");
String temp=new String(temp_t, "gb2312 ");
return temp;
}
catch(Exception ex){
System.err.println( "sq.executeUpdate: "+ex.getMessage());
return null;
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
int jj=0;
String[] s1=new String[100];
double[] s2=new double [100];
double maxs2=0;
response.setContentType( "image/jpeg;charset=8859_1 ");
ServletOutputStream out = response.getOutputStream();
int X=640;//X宽度
int Y=480;//Y宽度
int X_1=30;
int Y_1=30;
BufferedImage image = new BufferedImage(X,Y, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Graphics2D g2d= (Graphics2D)g;
g2d.setBackground(Color.blue);
//底色
g2d.setColor(Color.white);
g2d.fillRect(0,0,image.getWidth(),image.getHeight());
//JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
//encoder.encode(image);
//坐标
g.setColor(Color.black);
g.setFont(new Font( "Helvetica ",Font.PLAIN,12));
g.drawLine(X_1,Y_1,X_1,Y-Y_1);g.drawLine(X_1,Y-Y_1,X-X_1,Y-Y_1);
//Y坐标
//X坐标
int X0=(int)(500/(jj+1));
int x1=30;
int y1=450;
int x2;int y2;
g.drawString( getStr("中文字怎么还不出来呀 "),300,100);
g.drawString( "中文字怎么还不出来呀 ",300,100);
g.drawString( "thisis a bmp ",300,200);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
}
}
|
//package scs;
import java.io.*;
public class MyUtil
{
//
// 将GB2312码的字符串s转成Unicode码并返回
//
public static String gb2312ToUnicode(String s) {
try {
return new String(s.getBytes("ISO8859_1"), "GB2312");
}
catch (UnsupportedEncodingException uee) {
return s;
}
}
//
// 将Unicode码的字符串s转成GB2312码并返回
//
public static String unicodeToGB2312(String s) {
try {
return new String(s.getBytes("GB2312"), "ISO8859_1");
}
catch (UnsupportedEncodingException uee) {
return s;
}
}
}
管你什么系统,照单全收!!!
import java.io.*;
public class MyUtil
{
//
// 将GB2312码的字符串s转成Unicode码并返回
//
public static String gb2312ToUnicode(String s) {
try {
return new String(s.getBytes("ISO8859_1"), "GB2312");
}
catch (UnsupportedEncodingException uee) {
return s;
}
}
//
// 将Unicode码的字符串s转成GB2312码并返回
//
public static String unicodeToGB2312(String s) {
try {
return new String(s.getBytes("GB2312"), "ISO8859_1");
}
catch (UnsupportedEncodingException uee) {
return s;
}
}
}
管你什么系统,照单全收!!!
|
does your os support gb2312 or had you installed chinese enviroment in your os?
please check
echo $LANG
or
echo $LANGUAGE
please check
echo $LANG
or
echo $LANGUAGE
|
建议编译时,使用参数-encoding gb2312试试看.
|
不会,学习!
|
response.setContentType( "image/jpeg;charset=8859_1 ");
|
学习中~~~~~~~我还没在linux下用过JB呢
|
是不是你的linux不支持中文编码,用下面的程序看看你的系统编码file.encoding是什么:
public class PoorChinese {
public static void main(String[] args) {
System.getProperties().list(System.out);
}
}
public class PoorChinese {
public static void main(String[] args) {
System.getProperties().list(System.out);
}
}