【问题标题】:Classic ASP + Motobit Pure ASP Upload + UTF-8 Charset经典 ASP + Motobit 纯 ASP 上传 + UTF-8 字符集
【发布时间】:2016-03-24 10:47:47
【问题描述】:

在utf-8和我的所有页面中使用mysql数据库后,检查编码并包含

@ Language = VBScript CodePage = 65001

在HTML页面中,包括:

meta charset = "utf-8"

在我不得不更改上传系统之前,一切都非常顺利。 现在,我正在使用 Pure Asp Upload 来发送图像,这很棒,但我需要你的帮助,因为其他文本字段太疯狂了。

我做了一个非常简单的代码,只有一个文件字段和一个文本字段,只是为了举例说明,并在他取字段后不久给出一个 Response.End() 只是想看看会发生什么,但几天后没有成功,来帮忙。

Pure Asp Upload 版本为 2.06

<%@ Language=VBScript CodePage=65001%>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<!--#include file="../includes/pure-upload.asp"-->
<% Session.Timeout = 60 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%
sAction = Request.querystring("a_edit")

If sAction = "" Or IsNull(sAction) Then
    sAction = "I" ' Display Record
else
    Dim fupload: Set fupload = New ASPForm

    Server.ScriptTimeout = 2000
    fupload.SizeLimit = 4*1000000 'limit of size per whole form
    Const fsCompletted  = 0

    If fupload.State = fsCompletted Then 'Completted

    fupload.CharSet = Response.CharSet
    x_jogadorID = fupload("x_jogadorID")
    x_jogadorNome = fupload.Item("x_jogadorNome")

    meukarma = fupload.CharSet
    response.write x_jogadorNome & "-" & meukarma
    response.End()

    ElseIf fupload.State > 10 then
      Const fsSizeLimit = &HD
      Select case fupload.State
        case fsSizeLimit
            Session(ewSessionMessage) = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
            Session(ewSessionMessageTipo) = "error"
        case else 
            Session(ewSessionMessage) = "<Font Color=red>Erro no Formulário." & Form.State & "</Font><br>"
            Session(ewSessionMessageTipo) = "error"
      end Select
    End If 'Form.State = 0 then
End If 

%>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>teste</title>
</head>

<body>
<form name="fjogadoredit" id="fjogadoredit" action="teste.asp?a_edit=U" class="form-horizontal" method="post" enctype="multipart/form-data"  onSubmit="return EW_checkMyForm(this);" >
<input type="text" name="x_jogadorNome" id="x_jogadorNome" class="input-xlarge" maxlength="50" value="<%= Server.HTMLEncode(x_jogadorNome&"") %>">
<input type="file" id="x_jogadorFotoRosto" name="x_jogadorFotoRosto"  class="default">
</form>
</body>
</html>

我是一个注册测试的名字是Amésio,更改为:

amnésio

如果我早在第二行就把块放在下面,Amésio 的结果是

amnésio
<%
Response.AddHeader "Content-Type", "text/html; charset=utf-8"
response.Charset="utf-8"
%>

有人设法以这种方式使用这个组件,或者像它那样设法解决了吗?

【问题讨论】:

  • Pointer... 不要Server.HTMLEncode() 值,否则它会与您已经设置的编码背道而驰。如果编码正确,则无需进一步编码值。
  • 您是否尝试过写出Response.Charset 以查看它是否设置为UTF-8,因为在将其分配给fupload.CharSet 之前您似乎没有在页面中设置它您可以编辑吗问题并添加response.write x_jogadorNome &amp; "-" &amp; meukarma的输出?
  • 对不起,我的意思是Response.CodePage,如果不是65001,那是你的问题。在发送处理HTML之前设置它,你应该没问题。
  • 我在第一行代码上定义了代码页,所有包含的文件都被检查了,它们保存在 utf-8 上,只有Form.CharSet = Response.CharSet 没有解决我的问题...我尝试创建一个属性 get/设置为使用 65001。我真的知道我的 probelma 并不简单,但是,我的所有页面都正常工作......我尝试使用 persits.aspuload,并且,当从他那里设置代码页时,工作得很好,但我想使用 Pure Asp 上传。

标签: mysql utf-8 vbscript asp-classic upload


【解决方案1】:

在阅读本文之前,我建议您快速浏览一下这个答案

Understanding How IIS Processes ASP Encoding


对于您的具体问题,我认为这取决于不指定

Response.CodePage = 65001

明确地假设它是65001,在分配ASPForm.CharSet 属性给它之前没有检查它。

试试这个

<%@ Language=VBScript CodePage=65001%>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<!--#include file="../includes/pure-upload.asp"-->
<%
Session.Timeout = 60

sAction = Request.querystring("a_edit")

'Make sure both IIS and the Browser know how to process the page / response
Response.CodePage = 65001
Response.CharSet = "UTF-8"

If sAction = "" Or IsNull(sAction) Then
    sAction = "I" ' Display Record
else
    Dim fupload: Set fupload = New ASPForm

    Server.ScriptTimeout = 2000
    fupload.SizeLimit = 4*1000000 'limit of size per whole form
    Const fsCompletted  = 0

    If fupload.State = fsCompletted Then 'Completted

    fupload.CharSet = Response.CharSet
    x_jogadorID = fupload("x_jogadorID")
    x_jogadorNome = fupload.Item("x_jogadorNome")

    meukarma = fupload.CharSet
    response.write x_jogadorNome & "-" & meukarma

    ElseIf fupload.State > 10 then
      Const fsSizeLimit = &HD
      Select case fupload.State
        case fsSizeLimit
            Session(ewSessionMessage) = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
            Session(ewSessionMessageTipo) = "error"
        case else 
            Session(ewSessionMessage) = "<Font Color=red>Erro no Formulário." & Form.State & "</Font><br>"
            Session(ewSessionMessageTipo) = "error"
      end Select
    End If 'Form.State = 0 then
End If 

%>
<!doctype html>
<html>
<head>
<title>teste</title>
</head>

<body>
<form name="fjogadoredit" id="fjogadoredit" action="teste.asp?a_edit=U" class="form-horizontal" method="post" enctype="multipart/form-data"  onSubmit="return EW_checkMyForm(this);" >
<input type="text" name="x_jogadorNome" id="x_jogadorNome" class="input-xlarge" maxlength="50" value="<%= x_jogadorNome & "" %>">
<input type="file" id="x_jogadorFotoRosto" name="x_jogadorFotoRosto"  class="default">
</form>
</body>
</html>

【讨论】:

  • @user3067573 很好,您尝试了什么?您是否从 HTML 输入值中删除了 Server.HTMLEncode()?事实是,如果它对您不起作用,这将起作用您做错了什么,您的页面没有保存在UTF-8 (包括#include 文件) 是常见的。只是说“谢谢,但不工作”只是表明你缺乏承诺,让我不太愿意帮助你。祝你好运。
  • @user3067573 编码是一个复杂的问题,必须系统地解决,直到您了解如何在 IIS 中处理 ASP 页。这就是我提供detailed explanation 的原因。没有快速修复!
  • 抱歉@Lankymart 给您带来不便。我将结束这个问题,因为如果我已经尝试了最基本的命令,我没有必要的洞察力来理解他们的愤慨,正如他在上下文帖子中所解释的那样。还是谢谢你。
  • @user3067573 你关注我上面的cmets了吗?您仍未更新问题中的代码,因此我看不到您已尝试所有这些步骤,如果您更新问题会有所帮助。
【解决方案2】:

了解 IIS 如何处理 ASP 编码

与经典 ASP 中的所有编码问题一样,它有助于理解各种命令实现的目的(人们经常错误地使用它们,因为它似乎可以解决问题)

&lt;%@ Language = "VBScript" CodePage = 65001 %&gt;

这一行通常被误解,语法 &lt;%@"ASP @ Processing Directive",用于告诉 IIS 如何处理 ASP 页面,并且可能是正确处理编码时最重要的命令之一。

  • @Language 告诉 IIS 应该使用什么注册的活动脚本语言来处理 ASP 页。

  • @CodePage 告诉 IIS 应该使用什么 CodePage 来处理 ASP 页。如果页面已使用UTF-8 保存,则 IIS 需要知道在处理页面时它应该使用 CodePage 65001 (也称为UTF-8

这意味着@CodePage 应该始终与创建页面时使用的物理编码相匹配。您可能需要使用高级文本编辑器来解决这个问题,例如Notepad++ (在 GUI 窗口右下角的状态栏上显示编码)Visual Studio (有一个名为Advanced Save Options 的隐藏菜单命令,可以通过自定义菜单栏来访问)

&lt;% Response.CodePage = 65001 %&gt;

同样经常被误解,这个命令的目的是告诉 IIS 应该如何编码动态字符串(动态字符串是指使用Response.Write() 输出的任何内容)。可能是整个过程中最重要的部分,如果设置不正确或假设编码不匹配可能而且确实会发生。

&lt;% Response.CharSet = "UTF-8" %&gt;

当响应从服务器发送到客户端浏览器时,此命令在Content-Type HTTP 标头中设置;charset=utf-8,它告诉浏览器此响应应作为UTF-8 处理,而不是默认值。 含义代码如

Response.AddHeader "Content-Type", "text/html; charset=utf-8"

是多余的,不应使用。另外值得注意的是,Content-Type HTTP 标头也有一个命令

Response.ContentType = "text/html"

使它比以前更加多余。


有用的链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2010-10-29
    • 1970-01-01
    相关资源
    最近更新 更多