大家快来看啊!用WEBLOGIC发布JSP,向Excel中导入汉字怎么会是乱码?(此程序在Tomcat中运行正常)
以下是我生成EXCEL的代码:
<%@ page contentType="application/msexcel;charset=ISO8859_1"%>
<%@ page import ="com.centurysoft.njds.database.*,
com.centurysoft.njds.*,
java.util.HashMap,
java.util.*,
com.centurysoft.njds.util.*"%>
<%
request.setCharacterEncoding("GBK");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
String str_search_tmp="";
String str_search = "";
String strHTML = "";
String username = request.getParameter("username");
String name = request.getParameter("name");
String depart = request.getParameter("depart");
String room = request.getParameter("room");
String office = request.getParameter("office");
String occup = request.getParameter("occup");
String status = request.getParameter("status");
String strSQL ="";
String strSQL1 ="";
if ((depart == null )||(depart.equals(""))){
if ((office != null) && (!office.equals("")))
{
strSQL = "select a.userid,a.name as mingzhi,a.departmentid,a.Businessid ,b.name,b.id FROM tbl_user a ,tbl_code b where a.office=b.id ";
strSQL= strSQL+" and b.name like '%"+office+"%'";
str_search = str_search + "&office="+office+"";
}
}
if (office == null || (office.equals(""))){
if ((depart != null) && (!depart.equals("")))
{
strSQL = "select a.userid,a.username,a.name as mingzhi,a.departmentid,a.userbusiness,b.name,b.id FROM tbl_user a ,tbl_code b where a.departmentid=b.id ";
strSQL=strSQL+" and b.name like '%"+depart+"%'";
str_search = str_search + "&depart="+depart+"";
}
}
if(strSQL.equals(""))
strSQL = "select a.userid,a.username,a.name as mingzhi,a.departmentid,a.userbusiness FROM tbl_user a WHERE 1=1";
if ((username != null) && (!username.equals("")))
{
strSQL=strSQL+" and a.username like '%"+username+"%'";
str_search = str_search + "&username="+username+"";
}
if ((name != null) && (!name.equals("")))
{
strSQL=strSQL+" and a.name like '%"+name+"%'";
str_search = str_search + "&name="+name+"";
}
if ((room != null) && (!room.equals("")))
{
strSQL= strSQL+" and a.room like '%"+room+"%'";
str_search = str_search +"&room="+room+"";
}
if ((occup != null)&&(!occup.equals("0")))
{
strSQL = strSQL +" and a.userbusiness ="+occup+"";
str_search = str_search + "&occup="+occup+"";
}
if ((status != null) && (!status.equals("2")))
{
strSQL=strSQL+" and a.status ="+status+"";
str_search = str_search +"&status="+status+"";
}
//out.print(strSQL);
if(strSQL.equals(""))
strSQL = "select a.userid,a.username,a.name as mingzhi,a.departmentid,a.userbusiness FROM tbl_user ORDER BY userid";
else
strSQL = strSQL + " ORDER BY a.userid";
Cursor cursor = DataSetBean.getCursor(strSQL);
HashMap fields = cursor.getNext();
if(fields == null){
strHTML = "<TR><TD COLSPAN=7 HEIGHT=30 CLASS=column align=center>系统没有用户资源</TD></TR>";
}
else{
int i=1;
while(fields != null){
strHTML += "<TR>";
strHTML +="<TD CLASS=column2>"+i+"</TD>";
strHTML += "<TD CLASS=column2>"+(String)fields.get("USERNAME") + "</TD>";
strHTML += "<TD CLASS=column2>"+ (String)fields.get("MINGZHI") + "</TD>";
strHTML += "<TD CLASS=column2>"+ DbCode.getCode(Integer.parseInt((String)fields.get("DEPARTMENTID"))) + "</TD>";
strHTML += "<TD CLASS=column2>"+ DbCode.getCode(Integer.parseInt((String)fields.get("USERBUSINESS")))+ "</TD>";
strHTML += "</TR>";
i++;
fields = cursor.getNext();
}
}
response.setHeader("Content-disposition","inline; filename=UserExcel.xls");
%>
<SCRIPT LANGUAGE="JavaScript" src="Js/CheckForm.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkForm(){
var obj = document.frm1;
if(!IsNumber(obj.num.value,'显示条数')){
obj.num.focus();
obj.num.select();
return false;
}
}
function newWin(url){
window.open(url,"","left=10,top=10,width=750,height=350");}
function newWin1(url){
window.open(url);}
function delWarn(){
if(confirm('确定删除吗?')){
return true;
}
else{
return false;
}
}
//-->
</SCRIPT>
<html>
<head>
<title>
</title>
</HEAD>
<body>
<TABLE border=1 >
<tr bgcolor="#FFFFFF">
<TH>序号</TH>
<TH>用户帐号</TH>
<TH>用户姓名</TH>
<TH>所在部门</TH>
<TH>职务</TH>
</TR>
<%=strHTML%>
</TABLE>
<BR>
</body>
</html>
问题点数:0、回复次数:5Top
1 楼ejbcreate(小章)回复于 2003-12-03 17:23:21 得分 0
<%@ page contentType="application/msexcel;charset=ISO8859_1"%>
~~~试试改为:
<%@ page contentType="application/msexcel;charset=GBK"%>Top
2 楼blue999star(星星要挣钱,给爸妈买房子)回复于 2003-12-03 17:29:37 得分 0
<%@ page import ="com.centurysoft.njds.database.*,
com.centurysoft.njds.*,
java.util.HashMap,
java.util.*,
com.centurysoft.njds.util.*"%>
请问这样写,jsp能编译通过吗?
为什么不用gb2312字符集 ?Top
3 楼awaysrain(绝对零度)(既然选择了远方就要日夜前行)回复于 2003-12-04 15:58:01 得分 0
换字符集试试吧
to blue999star(星星要挣钱,养老婆)
这样写
<%@ page import ="com.centurysoft.njds.database.*,
com.centurysoft.njds.*,
java.util.HashMap,
java.util.*,
和这样写是一样的 com.centurysoft.njds.util.*"%>
<%@ page import ="com.centurysoft.njds.database.*">
<%@ page import ="com.centurysoft.njds.*">
<%@ page import ="java.util.HashMap">
……
Top
4 楼xiaolei_418()回复于 2003-12-05 13:19:15 得分 0
我也试过换字符,GBK,GB2312我都试验过可都没用啊Top
5 楼blue999star(星星要挣钱,给爸妈买房子)回复于 2003-12-05 13:36:03 得分 0
奥,呵呵~~~~~~ 谢谢楼上的。
确实是正确的,在idea 中不能这样写。Top




