Java HTML Escape htmlEscape(String input)

Here you can find the source of htmlEscape(String input)

Description

Escape input string suitable for HTML output.

License

Apache License

Parameter

Parameter Description
input Input string.

Return

String with most dangerous characters escaped.

Declaration

public static String htmlEscape(String input) 

Method Source Code

//package com.java2s;
/**/*from   w  w  w .j  a v  a2  s.c  om*/
 * Licensed to Neo Technology under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Neo Technology licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

public class Main {
    /**
     * Escape input string suitable for HTML output.
     * 
     * @param input Input string.
     * @return String with most dangerous characters escaped.
     */
    public static String htmlEscape(String input) {
        String ret = input.replaceAll("&", "&");
        ret = ret.replaceAll("<", "&lt;");
        ret = ret.replaceAll(">", "&gt;");
        return ret;
    }
}

Related

  1. htmlEscape(Object obj)
  2. htmlEscape(String html)
  3. htmlescape(String html)
  4. htmlEscape(String input)
  5. htmlEscape(String input)
  6. htmlEscape(String input)
  7. htmlEscape(String nonHTMLsrc)
  8. htmlEscape(String s)
  9. htmlEscape(String S)