❶ 怎樣讓jsp頁面的小腳本中輸出html標簽,而不是識別它,顯示相應的格式
import java.io.*;
public class Test{
public static String changeToHtml(String input)
{
if(input == null || input.length() == 0)
return "";
char c = ' ';
StringBuffer sb = new StringBuffer(input.length());
for(int i = 0; i < input.length(); i++)
{
c = input.charAt(i);
if(c == ' ')
{
sb.append(" ");
continue;
}
if(c == '<')
{
sb.append("<");
continue;
}
if(c == '>')
{
sb.append(">");
continue;
}
if(c == '\n'){
sb.append("<br> ");
continue;
}
if(c == '&' ){
sb.append("&");
continue;
}
else
sb.append(c);
}
return sb.toString();
}
public static String transform(String content)
{
content=content.replaceAll("&","&");
content=content.replaceAll("<","<");
content=content.replaceAll(" "," ");
content=content.replaceAll(">",">");
content=content.replaceAll("\n","<br>");
return content;
}
public static void main(String []args){
BufferedReader bw;
StringBuffer sb=new StringBuffer("");
String ss="";
long l=0;
try{
File file=new File("G:\\novel\\凡爾納\\海底兩萬里\\001.HTM");//隨意選的文件
System.out.println(file.getPath().toString());
bw=new BufferedReader(new FileReader(file));
while((ss=bw.readLine())!=null){
System.out.println(ss);
sb.append(ss);
}
bw.close();
for(int i=0;i<10;i++) sb.append(sb);//作一個大字串
}catch(IOException e){}
long a=0;
long b=0;
/*輸出使用()所用時間
*a=System.currentTimeMillis();
*changeToHtml(sb.toString());
*b=System.currentTimeMillis();
*System.out.println(b-a);
*此處正常顯示時間
*/
/*輸出使用transform()所用時間
*a=System.currentTimeMillis();
*transform(sb.toString());
*b=System.currentTimeMillis();
*System.out.println(b-a);
*發生內存溢出錯誤
*/
}
}
❷ jsp中怎麼把html中的標簽和內容按照原來的格式全部輸出不是把標簽過濾掉。
document.getElementById('...').innerHTML;
連同標簽嗎?那就:
document.getElementById('...').outerHTML;
你要用這個做什麼啊?
❸ .jsp里的標簽改成html類型的標簽。。。
<html>
<head>
<title>登陸頁面</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
</head>
<body>
<center>
<formaction="loginUser">
用戶名:<inputtype="text"name="username"/>
密碼:回<inputtype="password"name="password"/>
<inputtype="submit"value="確定答"/>
<inputtype="reset"value="重置"/>
</form>
</center>
</body>
</html>
❹ JSP中怎麼用正則表達式過濾HTML標簽
<xmp><font color='red'>hello</font></xmp>
加xmp標簽就行了
❺ 關於jsp頁面解析html標簽問題,請高手幫忙看看啦!
你有get和set方法嗎?
❻ 關於jsp中的html與java分離
jsp中的html與java本來就是分離抄的,java代碼是寫在<%%>之間的,部署後,服務端代碼先執行,然後才會跟html元素交互。
所有這些都是jsp特有的:
JSP注釋
<%--*****--%> 是不輸出到客戶端的注釋符。
<%!--*****--%> 是輸出到客戶端的注釋符。
指令元素
<%@ page contentType=」text/html」 %> 設置指定頁面內容類型
<%@ include ...%> 在翻譯階段引入一個文件
<%@ taglib ... %> 聲明一個頁面使用的,包含自定義行為的標記庫。
行為元素
<jsp:useBean> 使一個JavaBeans組件在該頁中可用
<jsp:setProperty> 設置JavaBeans的屬性值
<jsp:forward> 將對請求的處理轉交給一個servlet或JSP頁面
腳本元素
<%this is a scriptlet%> 嵌入腳本代碼
表達式元素
<%= this is an expression%> 嵌入java表達式
方法聲明
<%! this is a declaration%> 用於在JSP頁面的實現類中聲明變數和方法
❼ jQuery 過濾html標簽屬性的特殊字元
您好,如果在表單中需要提交一字元串,其中包含,< > " &字元時,當我們把這字元串顯示到jsp頁面時,會和html標簽產生沖突,導致web頁面的某些部分消失或者格式不正確。為了解決以上問題,需要在顯示之前,對字元串進行代碼過濾。
把字元串中的 < 替換為 &It;
> 替換為 >
" 替換為 "
& 替換為 &
這里給出一個靜態的過濾代碼,供大家參考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
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();
}
}
此時,只需在jsp中對字元串調用此方法(StringUtils.escapeHTMLTags(str))即可。
❽ JSP 網站 屏蔽HTML標簽 回復表情
你首先要有一台電腦 然後有開發軟體 然後用手敲代碼實現
夠詳細了吧!!!!!!
❾ 如何將jsp返回的數據去除掉標簽
您指的是html的標簽嗎?
如果是html標簽直接在jsp文件中刪除就可以了呀。
如果是字元串變數中的標簽可以用replaceAll方法通過正則表達式刪除標簽。
❿ 如何在jsp網頁中的文本框內防止輸入html標簽和腳本
校驗,除了[0-9a-zA-Z]之外都不能輸入