# Class JspRuntimeLibrary

java.lang.Object
org.apache.jasper.runtime.JspRuntimeLibrary

public class JspRuntimeLibrary extends Object
Bunch of util methods that are used by code generated for useBean, getProperty and setProperty.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final boolean`
  `GRAAL`
  Indicates whether the code is running under GraalVM native image.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JspRuntimeLibrary()`
  Public constructor to allow security classload.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `capitalize(String name)`
  Reverse of Introspector.decapitalize.
  `static Object`
  `coerce(String s, Class<?> target)`
  Coerces a string to the target type.
  `static boolean`
  `coerceToBoolean(String s)`
  Coerces a string to a boolean value.
  `static byte`
  `coerceToByte(String s)`
  Coerces a string to a byte value.
  `static char`
  `coerceToChar(String s)`
  Coerces a string to a char value.
  `static double`
  `coerceToDouble(String s)`
  Coerces a string to a double value.
  `static float`
  `coerceToFloat(String s)`
  Coerces a string to a float value.
  `static int`
  `coerceToInt(String s)`
  Coerces a string to an int value.
  `static long`
  `coerceToLong(String s)`
  Coerces a string to a long value.
  `static short`
  `coerceToShort(String s)`
  Coerces a string to a short value.
  `static Object`
  `convert(String propertyName, String s, Class<?> t, Class<?> propertyEditorClass)`
  Converts a string value to the target type, using a property editor if specified.
  `static void`
  `createTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, Class<?> propertyEditorClass)`
  Create a typed array.
  `static String`
  `escapeQueryString(String unescString)`
  Escape special shell characters.
  `static String`
  `getContextRelativePath(ServletRequest request, String relativePath)`
  Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.
  `static Method`
  `getReadMethod(Class<?> beanClass, String prop)`
  Gets the read method (getter) for a bean property.
  `static Throwable`
  `getThrowable(ServletRequest request)`
  Returns the value of the jakarta.servlet.error.exception request attribute value, if present, otherwise the value of the jakarta.servlet.jsp.jspException request attribute value.
  `static Object`
  `getValueFromBeanInfoPropertyEditor(Class<?> attrClass, String attrName, String attrValue, Class<?> propertyEditorClass)`
  Gets a value using a bean info property editor.
  `static Object`
  `getValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue)`
  Gets a value using the property editor manager.
  `static Method`
  `getWriteMethod(Class<?> beanClass, String prop)`
  Gets the write method (setter) for a bean property.
  `static Object`
  `handleGetProperty(Object o, String prop)`
  Gets the value of a bean property.
  `static void`
  `handleSetProperty(Object bean, String prop, boolean value)`
  Sets a bean property to the given boolean value.
  `static void`
  `handleSetProperty(Object bean, String prop, byte value)`
  Sets a bean property to the given byte value.
  `static void`
  `handleSetProperty(Object bean, String prop, char value)`
  Sets a bean property to the given char value.
  `static void`
  `handleSetProperty(Object bean, String prop, double value)`
  Sets a bean property to the given double value.
  `static void`
  `handleSetProperty(Object bean, String prop, float value)`
  Sets a bean property to the given float value.
  `static void`
  `handleSetProperty(Object bean, String prop, int value)`
  Sets a bean property to the given int value.
  `static void`
  `handleSetProperty(Object bean, String prop, long value)`
  Sets a bean property to the given long value.
  `static void`
  `handleSetProperty(Object bean, String prop, short value)`
  Sets a bean property to the given short value.
  `static void`
  `handleSetProperty(Object bean, String prop, Object value)`
  Sets a bean property to the given value.
  `static void`
  `handleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper)`
  Sets a bean property from an EL expression.
  `static void`
  `include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush)`
  Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand.
  `static void`
  `introspect(Object bean, ServletRequest request)`
  Sets bean properties from request parameters.
  `static void`
  `introspecthelper(Object bean, String prop, String value, ServletRequest request, String param, boolean ignoreMethodNF)`
  Sets a single bean property from a string value.
  `static void`
  `nonstandardSetTag(PageContext pageContext, String var, Object value, int scope)`
  This method parallels the logic of `SetSupport.doEndTag()`.
  `static void`
  `releaseTag(Tag tag, InstanceManager instanceManager)`
  Releases a tag and destroys its instance.
  `static void`
  `releaseTag(Tag tag, InstanceManager instanceManager, boolean reused)`
  Releases a tag and destroys its instance if it has not been re-used.
  `static JspWriter`
  `startBufferedBody(PageContext pageContext, BodyTag tag)`
  Starts a buffered body for a tag that supports body content.
  `static String`
  `toString(boolean b)`
  Converts a boolean to its string representation.
  `static String`
  `toString(byte b)`
  Converts a byte to its string representation.
  `static String`
  `toString(char c)`
  Converts a char to its string representation.
  `static String`
  `toString(double d)`
  Converts a double to its string representation.
  `static String`
  `toString(float f)`
  Converts a float to its string representation.
  `static String`
  `toString(int i)`
  Converts an int to its string representation.
  `static String`
  `toString(long l)`
  Converts a long to its string representation.
  `static String`
  `toString(short s)`
  Converts a short to its string representation.
  `static String`
  `toString(Object o)`
  Converts an object to its string representation.
  `static String`
  `URLEncode(String s, String enc)`
  URL encodes a string, based on the supplied character encoding.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### GRAAL

    public static final boolean GRAAL
    Indicates whether the code is running under GraalVM native image.

- ## Constructor Details

  - ### JspRuntimeLibrary

    public JspRuntimeLibrary()
    Public constructor to allow security classload.

- ## Method Details

  - ### getThrowable

    public static Throwable getThrowable(ServletRequest request)
    Returns the value of the jakarta.servlet.error.exception request attribute value, if present, otherwise the value of the jakarta.servlet.jsp.jspException request attribute value. This method is called at the beginning of the generated servlet code for a JSP error page, when the "exception" implicit scripting language variable is initialized.
    Parameters:
      `request` - The Servlet request
    Returns:
      the throwable in the error attribute if any

  - ### coerceToBoolean

    public static boolean coerceToBoolean(String s)
    Coerces a string to a boolean value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the boolean value, or false if the string is null/empty

  - ### coerceToByte

    public static byte coerceToByte(String s)
    Coerces a string to a byte value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the byte value, or 0 if the string is null/empty

  - ### coerceToChar

    public static char coerceToChar(String s)
    Coerces a string to a char value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the char value, or 0 if the string is null/empty

  - ### coerceToDouble

    public static double coerceToDouble(String s)
    Coerces a string to a double value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the double value, or 0 if the string is null/empty

  - ### coerceToFloat

    public static float coerceToFloat(String s)
    Coerces a string to a float value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the float value, or 0 if the string is null/empty

  - ### coerceToInt

    public static int coerceToInt(String s)
    Coerces a string to an int value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the int value, or 0 if the string is null/empty

  - ### coerceToShort

    public static short coerceToShort(String s)
    Coerces a string to a short value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the short value, or 0 if the string is null/empty

  - ### coerceToLong

    public static long coerceToLong(String s)
    Coerces a string to a long value.
    Parameters:
      `s` - The string to coerce
    Returns:
      the long value, or 0 if the string is null/empty

  - ### coerce

    public static Object coerce(String s, Class<?> target)
    Coerces a string to the target type.
    Parameters:
      `s` - The string to coerce
      `target` - The target class
    Returns:
      the coerced value

  - ### convert

    public static Object convert(String propertyName, String s, Class<?> t, Class<?> propertyEditorClass) throws JasperException
    Converts a string value to the target type, using a property editor if specified.
    Parameters:
      `propertyName` - The property name
      `s` - The string value to convert
      `t` - The target class
      `propertyEditorClass` - The property editor class, or `null`
    Returns:
      the converted value
    Throws:
      `JasperException` - if conversion fails

  - ### introspect

    public static void introspect(Object bean, ServletRequest request) throws JasperException
    Sets bean properties from request parameters.
    Parameters:
      `bean` - The bean
      `request` - The servlet request
    Throws:
      `JasperException` - if setting a property fails

  - ### introspecthelper

    public static void introspecthelper(Object bean, String prop, String value, ServletRequest request, String param, boolean ignoreMethodNF) throws JasperException
    Sets a single bean property from a string value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The string value
      `request` - The servlet request
      `param` - The parameter name
      `ignoreMethodNF` - Whether to ignore missing methods
    Throws:
      `JasperException` - if setting the property fails

  - ### toString

    public static String toString(Object o)
    Converts an object to its string representation.
    Parameters:
      `o` - The object
    Returns:
      the string representation

  - ### toString

    public static String toString(byte b)
    Converts a byte to its string representation.
    Parameters:
      `b` - The byte value
    Returns:
      the string representation

  - ### toString

    public static String toString(boolean b)
    Converts a boolean to its string representation.
    Parameters:
      `b` - The boolean value
    Returns:
      the string representation

  - ### toString

    public static String toString(short s)
    Converts a short to its string representation.
    Parameters:
      `s` - The short value
    Returns:
      the string representation

  - ### toString

    public static String toString(int i)
    Converts an int to its string representation.
    Parameters:
      `i` - The int value
    Returns:
      the string representation

  - ### toString

    public static String toString(float f)
    Converts a float to its string representation.
    Parameters:
      `f` - The float value
    Returns:
      the string representation

  - ### toString

    public static String toString(long l)
    Converts a long to its string representation.
    Parameters:
      `l` - The long value
    Returns:
      the string representation

  - ### toString

    public static String toString(double d)
    Converts a double to its string representation.
    Parameters:
      `d` - The double value
    Returns:
      the string representation

  - ### toString

    public static String toString(char c)
    Converts a char to its string representation.
    Parameters:
      `c` - The char value
    Returns:
      the string representation

  - ### createTypedArray

    public static void createTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, Class<?> propertyEditorClass) throws JasperException
    Create a typed array. This is a special case where params are passed through the request and the property is indexed.
    Parameters:
      `propertyName` - The property name
      `bean` - The bean
      `method` - The method
      `values` - Array values
      `t` - The class
      `propertyEditorClass` - The editor for the property
    Throws:
      `JasperException` - An error occurred

  - ### escapeQueryString

    public static String escapeQueryString(String unescString)
    Escape special shell characters.
    Parameters:
      `unescString` - The string to shell-escape
    Returns:
      The escaped shell string.

  - ### handleGetProperty

    public static Object handleGetProperty(Object o, String prop) throws JasperException
    Gets the value of a bean property.
    Parameters:
      `o` - The bean
      `prop` - The property name
    Returns:
      the property value
    Throws:
      `JasperException` - if getting the property fails

  - ### handleSetPropertyExpression

    public static void handleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper) throws JasperException
    Sets a bean property from an EL expression.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `expression` - The EL expression
      `pageContext` - The page context
      `functionMapper` - The function mapper
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, Object value) throws JasperException
    Sets a bean property to the given value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, int value) throws JasperException
    Sets a bean property to the given int value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, short value) throws JasperException
    Sets a bean property to the given short value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, long value) throws JasperException
    Sets a bean property to the given long value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, double value) throws JasperException
    Sets a bean property to the given double value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, float value) throws JasperException
    Sets a bean property to the given float value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, char value) throws JasperException
    Sets a bean property to the given char value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, byte value) throws JasperException
    Sets a bean property to the given byte value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### handleSetProperty

    public static void handleSetProperty(Object bean, String prop, boolean value) throws JasperException
    Sets a bean property to the given boolean value.
    Parameters:
      `bean` - The bean
      `prop` - The property name
      `value` - The value to set
    Throws:
      `JasperException` - if setting the property fails

  - ### capitalize

    public static String capitalize(String name)
    Reverse of Introspector.decapitalize.
    Parameters:
      `name` - The name
    Returns:
      the capitalized string

  - ### getWriteMethod

    public static Method getWriteMethod(Class<?> beanClass, String prop) throws JasperException
    Gets the write method (setter) for a bean property.
    Parameters:
      `beanClass` - The bean class
      `prop` - The property name
    Returns:
      the write method
    Throws:
      `JasperException` - if the property or write method cannot be found

  - ### getReadMethod

    public static Method getReadMethod(Class<?> beanClass, String prop) throws JasperException
    Gets the read method (getter) for a bean property.
    Parameters:
      `beanClass` - The bean class
      `prop` - The property name
    Returns:
      the read method
    Throws:
      `JasperException` - if the property or read method cannot be found

  - ### getValueFromBeanInfoPropertyEditor

    public static Object getValueFromBeanInfoPropertyEditor(Class<?> attrClass, String attrName, String attrValue, Class<?> propertyEditorClass) throws JasperException
    Gets a value using a bean info property editor.
    Parameters:
      `attrClass` - The attribute class
      `attrName` - The attribute name
      `attrValue` - The attribute value as a string
      `propertyEditorClass` - The property editor class
    Returns:
      the converted value
    Throws:
      `JasperException` - if conversion fails

  - ### getValueFromPropertyEditorManager

    public static Object getValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue) throws JasperException
    Gets a value using the property editor manager.
    Parameters:
      `attrClass` - The attribute class
      `attrName` - The attribute name
      `attrValue` - The attribute value as a string
    Returns:
      the converted value
    Throws:
      `JasperException` - if conversion fails

  - ### getContextRelativePath

    public static String getContextRelativePath(ServletRequest request, String relativePath)
    Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.
    Parameters:
      `request` - The servlet request we are processing
      `relativePath` - The possibly relative resource path
    Returns:
      an absolute path

  - ### include

    public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) throws IOException, ServletException
    Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand.
    Parameters:
      `request` - The servlet request we are processing
      `response` - The servlet response we are processing
      `relativePath` - The relative path of the resource to be included
      `out` - The Writer to whom we are currently writing
      `flush` - Should we flush before the include is processed?
    Throws:
      `IOException` - if thrown by the included servlet
      `ServletException` - if thrown by the included servlet

  - ### URLEncode

    public static String URLEncode(String s, String enc)
    URL encodes a string, based on the supplied character encoding.
    Parameters:
      `s` - The String to be URL encoded.
      `enc` - The character encoding
    Returns:
      The URL encoded String

  - ### startBufferedBody

    public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag) throws JspException
    Starts a buffered body for a tag that supports body content.
    Parameters:
      `pageContext` - The page context
      `tag` - The body tag
    Returns:
      the JspWriter for the body content
    Throws:
      `JspException` - if starting the buffered body fails

  - ### releaseTag

    public static void releaseTag(Tag tag, InstanceManager instanceManager, boolean reused)
    Releases a tag and destroys its instance if it has not been re-used.
    Parameters:
      `tag` - The tag to release
      `instanceManager` - The instance manager
      `reused` - Has the tag successfully been re-used

  - ### releaseTag

    public static void releaseTag(Tag tag, InstanceManager instanceManager)
    Releases a tag and destroys its instance.
    Parameters:
      `tag` - The tag to release
      `instanceManager` - The instance manager

  - ### nonstandardSetTag

    public static void nonstandardSetTag(PageContext pageContext, String var, Object value, int scope)
    This method parallels the logic of `SetSupport.doEndTag()`.
    Parameters:
      `pageContext` - pageContext
      `var` - name of the variable
      `value` - value to store
      `scope` - scope