導航:首頁 > 凈水問答 > 代理過濾html代碼

代理過濾html代碼

發布時間:2021-03-29 19:53:46

❶ java中如何過濾html的代碼

把需要寫入資料庫的字元通過下面的方法過濾然後內再寫入 public static String converthtml(String input) { if (input == null ||容 input.length() == 0) { return input; } StringBuffer buf = new StringBuffer(input.length() + 6); char ch = ' '; for (int i = 0; i < input.length(); i++) { ch = input.charAt(i); if (ch == '&') { buf.append("&"); } else if (ch == '<') { buf.append("<"); } else if (ch == '>') { buf.append(">"); } else if (ch == ' ') { buf.append(""); } else { buf.append(ch); } } return buf.toString(); }

希望採納

❷ 輸出數據時,如何過濾html代碼

這個方法在網上很流行的,你看看
<%
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進行匹配
Set Matches = objRegExp.Execute(strHTML)

' 遍歷匹配集合,並替換掉匹配的項目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function
%>

❸ 過濾除表格以外的所有html代碼,如何實現

public static string NoHTML(string Htmlstring)
{
//刪除腳本
Htmlstring=Htmlstring.Replace("'", "'");
Htmlstring = Regex.Replace(Htmlstring, @" <script[^>]*?>.*? </script>", "",RegexOptions.IgnoreCase);
//刪除HTML 下面一行刪除,涉及到表格裡面的table tr td
//Htmlstring = Regex.Replace(Htmlstring, @" <(.[^(table|tr|td|>)]*)>", "",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @" <!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", " <",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(|#169);", "\xa9",RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "",RegexOptions.IgnoreCase);
Htmlstring.Replace(" <", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}

上面已經修改,只用取消Htmlstring = Regex.Replace(Htmlstring, @" <(.[^(table|tr|td|>)]*)>", "",RegexOptions.IgnoreCase); 這一個就行了。

❹ 怎樣用js方法過濾html等代碼

^<input type="text" id="theOne" value="">
<input type="button" onclick="NoHtml()" value="過濾html標簽">
<script>
function NoHtml(){
var t=document.getElementById("theOne").value;
t=t.replace(/({|})/g,''); //過濾{}
t=t.replace(/</g,'<'); //置換符號<
t=t.replace(/>/g,'>'); //置換符號>
// t=t.replace(/<\/?[^>]*>/g,''); //*<\/?[^>]*>可以匹配<script></style></body>等,並置空。而不是替內換容<和>兩個符號
document.getElementById("theOne").value=t;
}
</script>

❺ 怎樣用js方法過濾html等代碼,如@

關鍵點制:

  1. 正則表達式,把要替換的內容用正則表達式表達出來,如字元串、數字、字母中文、標點符號等。

  2. replace() 方法,用於在字元串中用一些字元替換另一些字元,或替換一個與正則表達式匹配的子串。



上代碼:

<html>
<head>
<title>無標題文檔</title>
<metacharset="UTF-8">
</head>
<body>
<divid="main">文章內容@文章內容,文章內容@文章內容</div>
</body>

<script>
//獲取標簽中文本
vardoj_str=document.getElementById('main').innerText;
//要替換的字元串,最後的g表示全局匹配,例如又多個@
varreg_str=/@/g;
//替換為空
varnew_str=doj_str.replace(reg_str,'');
//輸出新字元串
document.write(new_str);
</script>

</html>

❻ 一套程序提交信息時把html部分代碼過濾了,怎麼寫才不會被過濾了

就看他的過濾是本地過濾還是伺服器過濾了,本地過濾的話一般用的是腳本過濾,只要在本地禁用腳本就可以,如果是伺服器端過濾的話那就沒辦法了,你只有找其他方法將他的伺服器許可權搞到手,將他的伺服器網頁程序改掉才行。

❼ 如何過濾HTML的標簽

這個很簡單的,一般後台向前端傳輸數據的時候都要經過相關的轉移和二者是相關的處理。將h
t
ml代碼轉換成字元串兒不讓瀏覽器解析。

❽ 怎麼過濾html標簽

過濾html標簽代碼如下:
public string checkStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //過濾<script></script>標記
html = regex2.Replace(html, ""); //過濾href=javascript: (<A>) 屬性
html = regex3.Replace(html, " _disibledevent="); //過濾其它控制項的on...事件
html = regex4.Replace(html, ""); //過濾iframe
html = regex5.Replace(html, ""); //過濾frameset
html = regex6.Replace(html, ""); //過濾frameset
html = regex7.Replace(html, ""); //過濾frameset
html = regex8.Replace(html, ""); //過濾frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}

❾ html代碼中如何實現注冊後才能訪問這個頁面

1 HTML本身是標簽,用於顯示和格式化數據,不支持邏輯.
2 想要支持邏輯,要麼使用頁面腳本語言javascript,通過發送一個非同步請求到後台伺服器,後台伺服器驗證請求的Client是否已經登錄,然後非同步返回一個結果,使用JS根據結果來決定是否跳出該頁面(此法不安全,不可靠,需要作大量的預防性工作)
3 使用伺服器頁面技術(通過伺服器程序決定返回什麼視圖 MVC框架)
4 單獨編寫伺服器代理過濾程序
以上方法自己選吧

❿ 過濾所有html標簽的幾種方法

<!DOCTYPE html>
<html lang="en">

<head>
屬<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript">
window.onload = function() {
var oTxt1 = document.getElementById('txt1');
var oTxt2 = document.getElementById('txt2');
var test = document.getElementById('test');

test.onclick = function() {
var reg = /<[^<>]+>/g;
oTxt2.value = oTxt1.value.replace(reg, '');
};
}
</script>
</head>

<body>
<div>
<input type="text" id="txt1">
<input type="text" id="txt2">
</div>
<div><button id="test">測試</button></div>
</body>

</html>

閱讀全文

與代理過濾html代碼相關的資料

熱點內容
溫嶺市污水辦 瀏覽:777
javaweb中過濾器 瀏覽:999
冰火玉液紅提蒸餾酒 瀏覽:466
空氣凈化器為什麼頭還暈 瀏覽:431
郵個飲水機需要多少錢 瀏覽:873
核電的污水對生態有影響嗎 瀏覽:157
白醋給地暖管除垢 瀏覽:946
回奶可以用哪些 瀏覽:733
空氣凈化器怎麼區分濾芯正反面 瀏覽:409
水處理標准 瀏覽:719
公司飲用水有很多水垢 瀏覽:261
ro反滲透匯通膜 瀏覽:488
物理實驗室不會產生廢氣廢水 瀏覽:783
工業廢水處理技術題目 瀏覽:851
紅塔集團過濾嘴廠自那裡 瀏覽:35
廢水站運行管理制度 瀏覽:181
孕期可以用芒硝回奶嗎 瀏覽:809
拋光樹脂不用水可以停嗎 瀏覽:12
愛惠浦復合濾芯怎麼拆 瀏覽:528
紅外光譜樹脂 瀏覽:786