Forums, chat rooms, in the filter HTML tags

  Abstract: The Forum, chat rooms are open systems, each an authority in which the user can speak freely … 

  The forum, chat rooms are open systems, each an authority in which the user can speak freely.    But there are some people with ulterior motives users will use their open disturbance in which, for example, in chat forums or in the article, embedded HTML tags, the system is chaotic.    Therefore, to prepare a robust discussion forum or chat room users must be sent to the HTML tag filtered. 

  Let us take a look at how these markers filtered.    As we all know, HTML tag is bracketed by the two Tsim "<",">" and composition of some of these statements, such as, as long as we receive the HTML language in the corresponding change "<",">" <and> in the back on it.    Now it more clear thinking.    Now let us look at this process in the Java program in how to achieve in order to save space, I can only write a filter function. 

  Public String htmlFilter (String inputString); 

  If (inputString.length () = = 0 | | inputString = = null) 

  ( 

  Return inputString; 

  ) 

  / / / Receive if the string is empty value or length of zero will return the string, 

  / / Empty string because it is impossible * the link "and> 

  StringBuffer str = new StringBuffer (inputString.length () +6); 

  / / Create a buffer space 

  Char c =''; 

  For (int i = 0; i <inputString.length (); i + +) 

  ( 

  C = inputString.charAt (i) / / each scan input string, removed inputString first i +1 characters 

  If (c = ='<') 

  ( 

  Str.append ("<"); 

  ) / / C: If '<', in the buffer str adding "<" instead of '<' 

  Else if (c = ='>') 

  ( 

  Str.append ("<"); 

  ) / / C if the '>', in the buffer str add ">" instead of '>' 

  Else 

  ( 

  Str.append (c); / / If neither '<' nor '>' c directly to the values enshrined in the buffer 

  ) 

  ) 

  Return str.toString (); / / filtration HTML tags string 

  ) 

  You see, the problem was a simple function of the Java resolved.    You just add it to your forums or chat on the proceedings held. 




  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply