简体   繁体   English

html转义字符

[英]html escape characters

I have the following: 我有以下内容:

<form name="input" method="get" action="http://site:8083/Default.aspx?DC=" target="foo" onSubmit="window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')">
<select name="DC">
<option value="1&Type=type1">1</option>
<option value="2&Type=type2">2</option>
<option value="3&Type=type3">3</option>
<option value="4&Type=type4">4</option>
<option value="5&Type=type5">5</option>
<option value="6&Type=type6">6</option>
<option value="7&Type=type7">7</option>
</select>
<input type="submit" value=">>"/>&nbsp;&nbsp;
</form>

Basically my querystring should be something like DC=1&Type=type1 the problem I have is that when I click the >> button above the html screws up the stirng by changing & to %26 and = to %3D 基本上我的查询字符串应该类似于DC = 1&Type = type1,我遇到的问题是,当我单击html上方的>>按钮时,通过将&更改为%26和=更改为%3D来拧紧搅拌

How can I make the value stay as I have it in the code above? 如何在上面的代码中保持其价值不变?

Forms are designed to submit key/value pairs of data where the key is the name of the control and the value is the value . 表单旨在提交键/值对数据,其中键是控件的name ,值是value They will not mash arbitrary strings together. 它们不会将任意字符串混在一起。

Design your server side program to expect input in the format the forms are designed to use. 设计服务器端程序,以期望表单设计使用的格式输入信息。

Yes, that's the expected behaviour, the HTTP GET works this way, values are encoded to difference from keys. 是的,这是预期的行为,HTTP GET以这种方式工作,值被编码为与键不同。 In GET, browsers append key=value pairs separated by '&' and starting with a '?'; 在GET中,浏览器会附加以'&'分隔并以'?'开头的键=值对; you shouldn't specify them by yourself in the url. 您不应该在网址中自行指定它们。

I think you should change your code in this way, maybe it's what you want to get: 我认为您应该以这种方式更改代码,也许正是您想要得到的:

<form name="input" method="get" action="http://site:8083/Default.aspx" target="foo" onSubmit="updateType()">
<select name="DC">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <!-- etc... -->
</select>
<input type="hidden" name="Type"/>
<input type="submit" value=">>"/>
</form>

and in Javascript...: 并使用Javascript ...:

function updateType(){
    // set up 'Type'
    document.forms[0].Type.value = 'Type' + document.forms[0].DC.value;
    // open popup
    window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')
    return true;
}

...and this is correct. ...这是正确的。 Request-Parameters [get] should be encoded. 请求参数[get]应该被编码。 When you get the Request, your Server should decode them [apache/php] or i don't know ASP but in php it gaves a function called urldecode() ... 当您收到请求时,您的服务器应将其解码[apache / php]或我不知道ASP,但是在php中,它提供了一个名为urldecode()的函数...

So what you're trying to do is have two different query string set to two different values when a single item on your form is set. 因此,您要执行的操作是在设置表单上的单个项目时将两个不同的查询字符串设置为两个不同的值。 While your attempted solution is a neat idea, clearly the browser is actively preventing you from using that method (for security reasons) and rightly so. 尽管您尝试的解决方案是一个很好的主意,但显然,浏览器正在积极阻止您使用该方法(出于安全原因),并且这样做是正确的。 I see two solutions that would work well for you. 我认为有两种解决方案将很适合您。

  1. Use the form to send just one query string (ie DC) and on the server side, determine what the value of 'Type' should be. 使用该表格仅发送一个查询字符串(即DC),然后在服务器端确定“ Type”的值应为什么。 If it's really, really important to have both values as query strings (for example you're re-using a Control that only looks at those query strings) then use Server.Transfer on the server side to add the additional query string(s). 如果两个值都作为查询字符串确实非常重要(例如,您正在重新使用仅查看那些查询字符串的控件),则在服务器端使用Server.Transfer添加其他查询字符串。

  2. Provide two types of inputs on the form. 在表单上提供两种输入。 One being the select box that you have there, another being either a hidden select box, a hidden input field, or whatever else fits for you. 一个是您在那里的选择框,另一个是隐藏的选择框,隐藏的输入字段或其他适合您的内容。 Add Javascript to the page such that when the selection is changed on the visible select box you set the hidden field to the correct value, then when the form is submitted both inputs are each submitting only one query string, as the browser is designed to support. 将Javascript添加到页面,以便在可见的选择框上更改选择时,将隐藏字段设置为正确的值,然后在提交表单时,两个输入均仅提交一个查询字符串,因为浏览器旨在支持。

Here's an implemention of choice #2: 这是选择#2的实现:

<script type="text/javascript">
var DCMapping = new Array();
DCMapping["1"] = "type1";
DCMapping["2"] = "type2";
DCMapping["3"] = "type3";
DCMapping["4"] = "type4";
DCMapping["5"] = "type5";
DCMapping["6"] = "type6";
DCMapping["7"] = "type7";
function selectionChanged(selectBox)
{
    alert(DCMapping[selectBox.value]);
    document.getElementById('hidType').value = DCMapping[selectBox.value];
}
</script>
<form name="input" method="get" action="http://site:8083/Default.aspx" target="foo" 
    onSubmit="window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')">
    <select name="DC" onchange="selectionChanged(this)">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
    </select>
    <input type="hidden" name="Type" id="hidType" value="1" />
    <input type="submit" value=">>"/>&nbsp;&nbsp;
</form>

Try using: 尝试使用:

HttpUtility.UrlDecode()

Further reading 进一步阅读

You should use: 您应该使用:

HttpUtility.UrlDecode();

To convert escape characters in the url 转换网址中的转义字符

You can remove the method and action from the <form> . 您可以从<form>删除方法和操作。 Instead extend the JavaScript/VBScript to pick up the value of the selected option and catenate it with the url root. 而是扩展JavaScript / VBScript以获取所选选项的值,并将其与url根进行分类。

You don't need to mess with url decoding, the %.. should work fine as-is. 您不需要弄乱url解码,%..应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM