一个解决jsp中文转换的方法

作者: ldsea 分类: 程序生活 发布时间: 2008-03-06 17:23

首先建立一个文件,include.inc,代码如下

[code]<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%!
  String trans(String chi)
{
  String result = null;
  byte[] temp;
  try{
    temp = chi.getBytes("gb2312");
    result=new String(temp);
  }
  catch(Exception e)
  {
    e.printStackTrace();
  }
  return result;
}
%>
<%–下面是测试的代码–%>
<%!
int count=10;
%>
<%
String source="海蓝博客";
for(int i=0;i<count;i++)
{
  out.print(trans(source)+"<br>");
}
%>[/code]
这样,当其他页面需要使用时,include指令就把它包含进来,如:
[code]<%@ include file="include.inc"%>[/code]

发表回复

您的电子邮箱地址不会被公开。