网页显示正常,查看源代码中文mysql字符乱码全是乱码.

网页能正常显示,但查看源代码中的汉字全是乱码?
[问题点数:20分,结帖人ljxjtu]
网页能正常显示,但查看源代码中的汉字全是乱码?
[问题点数:20分,结帖人ljxjtu]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。asp关于查看源代码出现乱码的解决
今天在开发WEB页面过程中查看网页源代码的时候中文出现乱码的情况,因为在页面中没显式注明gb2321,所以页面默认为UTF8了。后来看了下面的文章在Page_load事件里面加上了Session.CodePage=936问题解决了。
昨天做了两个asp页面,一个是utf-8得页面一个则是gb2312得页面.
于是发生了件怪事(主要是我第一次遇见得),单独打开这两个页面都不会出现问题,
但偏偏从utf8连接到gb2312得时候就出现了乱码.花了两个小时都搞不掉,
今天再次打开,baidu了下结果.
后来发现两个解决方案
第一:在每个gb2312页面上设置Session.CodePage=936
这样问题就解决了...
第二:从utf8转到gb2312得时候不要用&a&连接.用response.redirect跳转,也能解决.
综上,我理解为
给每个页面设置CodePage这样就把各个页面得编码都独立起来,不再受相连页面得影响
其次&a&标签连接会将页面编码属性也传递给下一个页面,而使用redirect就不会出现这样得情况了,这跟
用asp得环境变量取Request.ServerVariables("HTTP_REFERER")一样,后者就取不到.
对于ASP编码问题的深入研究与最终解决方案
哪的资料都不如官方资料权威。今天总算从MSDN中择出了ASP编码问题的解决方案。
下面是MSDN中的一段话。
Setting @CODEPAGE explicitly affects literal strings in a single
response. Response.CodePage affects dynamic strings in a single
response, and Session.CodePage affects dynamic strings in all
responses in a session.
这句话解释清楚了@CODEPAGE,Response.CodePage,Session.CodePage
分别的作用是什么。
@CODEPAGE作用于所有静态的字符串,比如某文件中的 const
blogname="我的家"
Response.CodePage,Session.CodePage作用于所有动态输出的字符串,比如&%=blogname%&
这句话很关键的是说明了Response.CodePage的作用范围是a single
response,而SXNA中声明的Session.CodePage的作用范围是all responses
in a session。
再看另外一句话。
If Response.CodePage is not explicitly set in a page, it is
implicitly set by Session.CodePage, if sessions are enabled. If
sessions are not enabled, Response.CodePage is set by @CodePage, if
@CodePage is present in the page. If there is no @CodePage in the
page, Response.CodePage is set by the AspCodePage metabase
property. If the AspCodePage metabase property is not set, or set
to 0, Response.CodePage is set by the system ANSI code page.
这句话我乍一看,把意思理解成了这样:在sessions are
enabled的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。如果sessions
are not enabled的时候,
如果@CodePage已声明,则Response.CodePage会被@CodePage赋值,等等.............
这句话解释了为什么从SXNA中出来以后进入一些别的页面比如oblog,z-blog等等容易出现乱码,因为其他程序没有声明Response.CodePage而恰巧SXNA声明了Session.CodePage,因此一进入SXNA,Session.CodePage立即被赋值(版本不同,有的版本赋了936有的版本赋了65001),而后进入其他程序的时候Response.CodePage马上被Session.CodePage赋值,如果这时Response.CodePage与页面本身编码不一样的话,页面就会出现乱码。所以进入z-blog出现乱码的时候我查了当时的Session.CodePage和Response.CodePage都是936,而进入oblog出现乱码的时候Session.CodePage和Response.CodePage都是65001.就是说要想保证叶面不出现乱码,应该声明Response.CodePage,否则他就会按照Session.CodePage来解释网页(而不是按照@codepage解释网页).
如果仅仅按照上面的解释的话,我实际上是很糊涂的,因为我们都是用的中文操系统,当每一次进入浏览器的时候你可以尝试输出Session.CodePage,能看到他都是936!为什么进入Z-blog的时候他不把默认的Session.CodePage的936赋给Response.CodePage呢?反而把@CodePage给了Response.CodePage?什么情况下Session.CodePage才赋值给Response.CodePage呢?原文的sessions
are enabled应该如何理解呢?
也许上面的话应该这样理解:
在Session.CodePage被任何程序声明的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。如果Session.CodePage没有被任何程序声明的时候,
如果@CodePage已声明,则Response.CodePage会被@CodePage赋值,....,最后的页面动态内容部分按照Response.CodePage的值解释。
因为Zblog和Oblog都声明了@CodePage,所以,用户刚刚启动完机器然后进入浏览器浏览Zblog和Oblog的时候Response.CodePage会被@CodePage赋值,于是叶面显示正常。
这句话进一步解释了产生乱码的原因
If you set Response.CodePage or Session.CodePage explicitly, do
so before sending non-literal strings to the client. If you use
literal and non-literal strings in the same page, make sure the
code page of @CODEPAGE matches the code page of Response.CodePage,
or the literal strings are encoded differently from the non-literal
strings and display incorrectly.
其中比较有用的一句话是说如果Response.CodePage和@CODEPAGE不一样的话会产生乱码。也就是说当Z-blog的@CODEPAGE=65001而Z-blog的Response.CodePage被Session.CodePage赋为936的时候就会出现乱码,oblog反之亦然。
不知道上面说了这么多解释清楚没有-_-||
下面解释一下为什么SXNA有时会把Session.CodePage赋为936,我有一个版本是这样写的:
&% OriginalCodePage=Session.CodePage %&
&% Session.CodePage=OriginalCodePage %&
当用户进入浏览器的时候Session.CodePage默认为936,这个时候的默认936不是程序声明的,因此不会赋给Response.CodePage,当进入SXNA的时候,Session.CodePage被上面那段代码一折腾就变成了程序声明的Session.CodePage=936,因此再进入Zblog的时候就把936给了Response.CodePage。
至此,全部原因已经分析清楚了。
因此说,保证asp叶面一定不会出现乱码的代码应该是这样的:(假定是UTF-8的叶子)
&%@ CODEPAGE=65001 %&
&% Response.CodePage=65001%&
&% Response.Charset="UTF-8" %&
进一步说明为什么要加Response.Charset,因为MSDN说应该加...呵呵
If the code page is set in a page, then Response.Charset should
also be set.
另外,文件的编码格式应该与@CODEPAGE一样:
The file format of a Web page must be the same as the @CODEPAGE
used in the page.
这就是为什么zblog,pjblog等一些程序要吧文件存成UTF8编码格式的原因.
综上,如果所有的程序都声明了Response.CodePage就不会被Session.CodePage干扰而出现乱码了。所以Session.CodePage还是不能轻易用的!
参考文章:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。我的一个php页面能正常运行,但是里面的JavaScript的中文却显示的是乱码
[问题点数:20分,结帖人ImGoTop]
我的一个php页面能正常运行,但是里面的JavaScript的中文却显示的是乱码
[问题点数:20分,结帖人ImGoTop]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。查看: 2158|回复: 12
ATmega32L单片机与PC机的UART通信,寄存器UDR读取的字符总是乱码,高人请指点!(部分源码)
UART初始化程序:
void uart0_init(void)
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) ;&&//UCSRC select
UCSRC |= 0x06;//设置字符长度8位
UBRRL = 0x51; //set baud rate 9600
UBRRH = 0x00;
UCSRB = 0x98; //Enable Rx interrupt & Rx\Tx Function
串口中断程序:
#pragma interrupt_handler uart0_rx_isr:14
//定义串口接收中断服务函数[ISR=Interrupt Service Routine]
void uart0_rx_isr(void)
tmpRecv = UDR;& && &&&//Transmit UDR to TempReceiver
Receive_ok = 1;& && & //接收数据帧完成
主程序循环:
while(1)& && && &//主程序循环
{& & & &&&
& & & & if (Receive_ok == 1)
& && && && &Receive_ok=0;
& & & &&&LCD_Clear();
& & & &&&while(1){
& & & &&&& & & & C_Write(0x85);&&//写显示地址
& & & &&&& & & & D_Write(tmpRecv);&&//显示
8M晶振,9600 baudrate,u2x位置0时
波特率寄存器是不是可以
UBRRL=0x51;& && && & //资料上给的值是16进制的吗?
UBRRH=0x00;
mega32的资料里对UDR寄存器有以下描述:
接收缓冲器包括一个两级FIFO,一旦接收缓冲器被寻址FIFO就会心迹它的状态。因此不要对这一存储单元使用读-修改-写指令。
是不是说直接用
tmpRecv=UDR;& && && && &//已定义tmpRecv为全局变量unsigned char
指令读取UDR会出问题。
请牛牛们指点啊!
UBRRL = 51;// 是十进制的,不是0x51
UBRRL那个问题已经改了,但问题还是没有解决。。。。
现在是UBRRL=0x31;
UBRRH=0x00;
原来是乱码,现在是什么都不显示。。。
公益广告:本论坛不得使用、宣传Q群。 有讨论请在论坛里进行。 违者将封锁ID.
还有一个问题,如果TIMER0工作不正常的话,会不会影响到串口通讯啊?
公益广告:发表招聘帖子需要缴费,有需要可以联系网站工作人员王小姐:.
不理解你,0x31 = 51 ?
要么你写UBRRL = 51,要么写 UBRRL = 0x33 ;// 不是0x31
0x31 是啥,8 M晶振没有这个值,看看列表(8M晶振):
标准波特率 实际波特率&&误差(%)&&UBRR(HEX)
& && &&&50& && && &50& & 0.00&&F)
& && &&&75& && && &74& & 1.33&&A)
& && & 110& && &&&110& & 0.00&&)
& && & 150& && &&&150& & 0.00&&)
& && & 200& && &&&200& & 0.00&&)
& && & 300& && &&&299& & 0.33&&)
& && & 600& && &&&600& & 0.00& &832(0340)
& && &1200& && & 1199& & 0.08& &416(01A0)
& && &2400& && & 2403& &-0.13& &207(00CF)
& && &4800& && & 4807& &-0.15& &103(0067)
& && &7200& && & 7246& &-0.64& & 68(0044)
& && &9600& && & 9615& &-0.16& & 51(0033)
& &&&14400& && &14285& & 0.80& & 34(0022)
& &&&19200& && &19230& &-0.16& & 25(0019)
& &&&28800& && &29411& &-2.12& & 16(0010)
& &&&38400& && &38461& &-0.16& & 12(000C)
& &&&57600& && &55555& & 3.55& &&&8(0008)
公益广告:广告只能发在本论坛的广告区,否则将封锁ID。
主程式有问题,LCD操作慢,串口可能接收几次才写一1次LCD,串口数据要缓冲
问题解决了,跟大家分享下,不过是试出来的,还请高手指点:
问题出处:
UCSRC = BIT(URSEL) ;&&//UCSRC select
UCSRC |= 0x06;//设置字符长度8位
实际结果是UCSRC没能初始化到0x86;而只是0x80;
导致设置的位数为5BIT传输,于是出现了后面乱码的问题
改为UCSRC =BIT(URSEL) |0x06;后就没问题了,
不过我个人还是不理解为什么会出现这种区别。。
谁能解释一下!
楼主好厉害,终于被你搞定了~~呵呵&&楼主的意思是 UCSRC |= 0x06;这句话没有执行吗?
这样的话确实很奇怪~ 有源码吗? 有点话我也想测试一下
有,源码如下:
//ICC-AVR application builder :
// Target : M32
// Crystal: 8.0000Mhz
/******************************
Project& && && && &&&:TS Generator
Chip Type& && && && &:ATmega32L
Clock Frequency& && &:8.000000Mhz
Author& && && && && &:Garfield
From& && && && && &&&:BJUT Embeded Lab
Date& && && && && &&&:06.11.17
******************************/
//常用符号定义
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define FLAG struct flag
#define key_scan flag1.bit0
#define lcd_ok& &flag1.bit1
#define usart_ok flag1.bit2& && && & //已弃用
#define keydown&&flag1.bit3
#define Receive_ok flag1.bit4
#define Transmit_ok flag1.bit5
//Signal bit definitions
#define& & & & LED_G& & & & 4& & & & //PC4
#define& & & & key_cancel& & & & 2& & & & //PD2
#define& & & & key_down& & & & 3& & & & //PD3
#define& & & & key_confirm& & & & 4& & & & //PD4
#define& & & & key_right& & & & 5& & & & //PD5
#define& & & & key_left& & & & 6& & & & //PD6
#define& & & & key_up& & & & 7& & & & //PD7
/* LCDM 控制位&信号位 */
#define RS& && &2
#define RW& && &1
#define E& && & 0
#define BF& && &7
//常量定义
#define Baud&&9600
//定义全局变量
unsigned char ms,sec,tmpRecv,key_status,key1,lcdcounter,m;
unsigned char RecvData[80];& & & & & & & && && && && && &//接收到的上位机数据
unsigned char Wait[32]=&System Checking , Please Wait .& ;& &//空格ASC码:0x20
& &unsigned bit0:1;
& &unsigned bit1:1;
& &unsigned bit2:1;
& &unsigned bit3:1;
& &unsigned bit4:1;
& &unsigned bit5:1;
& &unsigned bit6:1;
& &unsigned bit7:1;
#include &iom32v.h&
#include &macros.h&
#include &stdio.h&
/****************************************************************
* 函数定义
****************************************************************/
unsigned char C_Read(void);
void C_Write(unsigned char cmd);
unsigned char D_Read(void);
void D_Write(unsigned char data);
void KEYSCAN(void);
unsigned char&&Key_Coding(uchar key_value);
void LCD_WR (uchar lcddata);
void LCD_Moveto(uchar position);
void LCD_Clear(void);
void init_devices(void);
void LCD_Stringin(uchar ddata[]);
//unsigned char ReceiveByte( void );
void main(void)
& &uchar m0=0;
& &uint a=1000;
& &init_devices();
& &while(Receive_ok == 0)
& & & && &&&NOP();
//& && & lcdcounter = 40;
& && && & C_Write(0x80);
& && && & lcdcounter=0;
& && &&&LCD_Stringin(Wait);& &//显示等待界面
& && &&&D_Write(' ');
& && &&&D_Write(' ');
& && &&&D_Write(' ');
& && &&&if(m==1)
& && &&&{ C_Write(0x9F);
& && && & D_Write('.');}
& && && & if(m==2)
& && && & {C_Write(0x9F);
& && && & D_Write('.');
& && && & D_Write('.');& & & & & & & & }
& && && & if(m==3)
& && && & {C_Write(0x9F);
& && && & D_Write('.');
& && && & D_Write('.');& & & &
& && && & D_Write('.');& & & &
& && && & }
& && && & if(m==4)
& && && & m=0;
& & & && &}
& &TCCR0 = BIT(CS02)&~BIT(CS01)|BIT(CS00); //start Timer& & choose clk =Clk/1024
& & & &&&//PORTC&= ~BIT(LED_G);& && && && && && && &//LED enable
while(1)& && && &//主程序循环
{& & & &&&
& & & && &if (Receive_ok == 1)& && && && && && && && && &&&//串口接收
& & & && &&&Receive_ok = 0;
& & & && & D_Write(tmpRecv);
& & & && &&&
& & & &&&if(m0&79)& && &&&//若数组溢出,复位
& & & &&&{& &m0 = 0;
& & & &&&}
& & & && &
& && & & &
void port_init(void)
PORTA = 0xFF;
DDRA&&= 0xFF;& && && &//A口配置为液晶Data Bus
PORTB = 0x18;& && && &//PB4和PB3内部上拉电阻使能
DDRB&&= 0x47;& && && &//配置PB2:PB0为输出[LCD控制端]
PORTC = 0xC0;& && && &//PC7~PC6上拉
DDRC&&= 0x30;& && && &//PC4配置为输出[LED_G]
PORTD = 0xFD;& && &&&
DDRD&&= 0x02;& && && &//PD1配置为输出[TXD]
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
//UCSRC = BIT(URSEL) ;&&//UCSRC select
//UCSRC |= 0x06;//设置字符长度8位
UBRRL = 0x33; //set baud rate 9600
UBRRH = 0x00;
UCSRB = 0x98; //Enable Rx interrupt & Rx\Tx Function
#pragma interrupt_handler uart0_rx_isr:14
//定义串口接收中断服务函数[ISR=Interrupt Service Routine]
void uart0_rx_isr(void)
tmpRecv = UDR;& && &&&//Transmit UDR to TempReceiver
Receive_ok = 1;& && & //接收数据帧完成
// usart_ok&&= 1;& && && &//进入串口操作模块
//tmpRecv = retu();
//LCD初始化,设置相关参数
void lcd_init(void)
C_Write(0x38);& && && && &//8位,两行,5*7
C_Write(0x0c);& && && && &//整体显示,关光标,关闪烁
C_Write(0x06);& && && && &//输入方式:增量不移位
C_Write(0x14);
C_Write(0x01);& && && && &//清屏
lcdcounter = 0;& && && && &//地址计数器归零
//液晶清屏
void LCD_Clear(void)
C_Write(0x01);& && && & //清DDRAM和AC值
lcdcounter = 0;& && && &//计数器归零
//call this routine to initialize all peripherals
void init_devices(void)
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
uart0_init();
lcd_init();& && &//自定义,初始化液晶
tmpRecv = 0;& &&&//变量初始化
key_status = 'W';
// flag1.bit0 = 0;
key_scan = 0 ;& &//位变量初始化
lcd_ok& &= 0 ;
keydown&&= 0 ;
Receive_ok = 0 ;
Transmit_ok = 0 ;&&
MCUCR = 0x00;& & //特殊寄存器初始化
GICR&&= 0x00;
TIMSK = 0x01; //timer interrupt sources//T/C0中断使能
SEI(); //re-enable interrupts
//all peripherals are now initialized
/****************
LCD底层驱动函数
*****************/
//指令读[BF/AC]
unsigned char C_Read(void)
uchar i =0;& &//06.11.24
PORTB &=~BIT(RS);
PORTB |=BIT(RW);
PORTB |=BIT(E);& &&&//RS=0,RW=1,Enable=1;
DDRA&&= 0x00;
NOP();& && && && && && && && && && && &//宏定义 空操作
i = PINA;&&
PORTB &= ~BIT(E);& && && && && && && & //Disable E
DDRA = 0xFF;& && && && && && && && && &//Reset portA as output
void C_Write(unsigned char cmd)
// busy = C_Read();& && && && && && && & //06.11.24
while((C_Read()&BIT(BF)) !=0)& &
PORTB &=~BIT(RS);
PORTB &=~BIT(RW);
PORTB |=BIT(E);& &//RS=0,RW=0,Enable=1
DDRA&&= 0xFF;
PORTB &= ~BIT(E);& && && && && && && & //disable E
PORTA = 0xFF;
void D_Write(unsigned char data)
// C_Read();& && && && && && && && & //06.11.24
while((C_Read()&BIT(BF)) !=0);& && && && && & //等待LCD空闲
PORTB |=BIT(RS);
PORTB &=~BIT(RW);
PORTB |=BIT(E);& &//RS=1,RW=0,Enable=1
DDRA=0& && && && && && && && && && && && && &&&//protA output
//if(data!='
//PORTA = 0x00;
&&NOP();& && && && && && &//宏定义,延时消抖
PORTB &=~BIT(E);& && && && && && && & //disable E
PORTA = 0xFF;& & & &&&
/***************
LCD模块应用程序
****************/
//将字符串写入LCD
void LCD_Stringin(uchar ddata[])
&&uchar i=0;
&&while (ddata!=0)& && &&&//若字符串数组未传完
//&&while (i&=19)
&&/*& & & &
& & if(ddata=='
&&{lcdcounter = 40;
& & LCD_Moveto(40);
& & & & while ((C_Read()&BIT(BF)) != 0)
& & & && &&&;
& & & && &&&i++;
& & & && &&&}
& & & & else& & if(ddata=='\r')
&&& & & & {lcdcounter = 40;
& & LCD_Moveto(40);
& & & & while ((C_Read()&BIT(BF)) != 0)
& & & && &&&;
&&& & & & i++;}
&&LCD_WR(ddata);&&
&&lcdcounter=0;
//将数据写入DDRAM当前地址
void LCD_WR (uchar lcddata)
if(lcdcounter == 40)& && && && && &&&//写入至首行末
& & LCD_Moveto(40);
& & & & while ((C_Read()&BIT(BF)) !=0)
& & & && & ;
& &}& & & &
if& & & & (lcdcounter == 80)& && && && && &//写入至次行末
& & & &&&LCD_Moveto(0);
& &&&lcdcounter =0;
& & & &&&while ((C_Read()&BIT(BF)) != 0)
& & & && &&&;
& & if(lcddata == '&')& && && && && &//若读至换行符
& & lcdcounter = 40;
& & LCD_Moveto(40);
& & & & while ((C_Read()&BIT(BF)) != 0)
& & & && &&&;
& &}& & & && &
&&else{& &
&&D_Write(lcddata);
& & lcdcounter++;}
//将光标指向DDRAM相应地址(0~79)
void LCD_Moveto(uchar position)&&
uchar command = 0x80;& && && && &&&//DDRAM基址
if(position&39)& && && && && && &&&//次行地址修改
& & position += 0x18;
command = command|& && &&&//基址+偏移地址
C_Write(command);
不是用GCC写的? 真郁闷,机子还没装ICC呢,以前装过ICC,好像鼠标中键滚动不能用,不知道是不是这样?
用ICC写和用GCC写有什么大的区别吗?
不都是C吗?
只要找一个ICC目录下的macros.h文件放到GCC的lib文件夹下
再把头文件改成#include&avr/io.h&
#include&avr/macros.h&
就可以了,这样的话我用GCC调试通过的
而macros.h也只是一个宏定义的头文件,实在没有也没关系,只要你辛苦点把程序里的
NOP();改成asm(&nop&);
BIT(XX);改成(1&&XX);
应该就没有问题了.
嗯,说得不错,原来是这样移植的,学习了~
只是我现在没装ICC,所以不方便;
以前装过ICC,好像鼠标中键滚动不能用,不知道是不是这样?
另外:程序中还用到了#pragma interrupt_handler uart0_rx_isr:14中断,这个要移植吗?#include &avr/macros.h&也包含了中断的定义吗?
ICC鼠标中键肯定能用没问题
macros.h只是宏定义的,与中断无关
#pragma ..的用法是C中比较复杂的一块,好像和编译器关系很大...GCC的帮助文档里你搜下吧,可能有
阿莫电子论坛, 原"中国电子开发网"你好。用你的方法测试了一个网站。发现源码还是乱码的。页面显示的有部分乱码。是不是转换方式不对?Kaka 于
11:33:48 回复objstream.Charset = &GB2312& 和 objstream.Charset = &UTF-8& 都是乱码吗?使用你网页的编码来转码看看。
AdSense专题
Powered By
Designed by Han'space}

我要回帖

更多关于 mysql字符乱码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信