Class JspRuntimeLibrary
java.lang.Object
org.apache.jasper.runtime.JspRuntimeLibrary
Bunch of util methods that are used by code generated for useBean, getProperty and setProperty.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanIndicates whether the code is running under GraalVM native image. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalize(String name) Reverse of Introspector.decapitalize.static ObjectCoerces a string to the target type.static booleanCoerces a string to a boolean value.static byteCoerces a string to a byte value.static charCoerces a string to a char value.static doubleCoerces a string to a double value.static floatCoerces a string to a float value.static intCoerces a string to an int value.static longCoerces a string to a long value.static shortCoerces a string to a short value.static ObjectConverts a string value to the target type, using a property editor if specified.static voidcreateTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, Class<?> propertyEditorClass) Create a typed array.static StringescapeQueryString(String unescString) Escape special shell characters.static StringgetContextRelativePath(ServletRequest request, String relativePath) Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.static MethodgetReadMethod(Class<?> beanClass, String prop) Gets the read method (getter) for a bean property.static ThrowablegetThrowable(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 ObjectgetValueFromBeanInfoPropertyEditor(Class<?> attrClass, String attrName, String attrValue, Class<?> propertyEditorClass) Gets a value using a bean info property editor.static ObjectgetValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue) Gets a value using the property editor manager.static MethodgetWriteMethod(Class<?> beanClass, String prop) Gets the write method (setter) for a bean property.static ObjecthandleGetProperty(Object o, String prop) Gets the value of a bean property.static voidhandleSetProperty(Object bean, String prop, boolean value) Sets a bean property to the given boolean value.static voidhandleSetProperty(Object bean, String prop, byte value) Sets a bean property to the given byte value.static voidhandleSetProperty(Object bean, String prop, char value) Sets a bean property to the given char value.static voidhandleSetProperty(Object bean, String prop, double value) Sets a bean property to the given double value.static voidhandleSetProperty(Object bean, String prop, float value) Sets a bean property to the given float value.static voidhandleSetProperty(Object bean, String prop, int value) Sets a bean property to the given int value.static voidhandleSetProperty(Object bean, String prop, long value) Sets a bean property to the given long value.static voidhandleSetProperty(Object bean, String prop, short value) Sets a bean property to the given short value.static voidhandleSetProperty(Object bean, String prop, Object value) Sets a bean property to the given value.static voidhandleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper) Sets a bean property from an EL expression.static voidinclude(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand.static voidintrospect(Object bean, ServletRequest request) Sets bean properties from request parameters.static voidintrospecthelper(Object bean, String prop, String value, ServletRequest request, String param, boolean ignoreMethodNF) Sets a single bean property from a string value.static voidnonstandardSetTag(PageContext pageContext, String var, Object value, int scope) This method parallels the logic ofSetSupport.doEndTag().static voidreleaseTag(Tag tag, InstanceManager instanceManager) Releases a tag and destroys its instance.static voidreleaseTag(Tag tag, InstanceManager instanceManager, boolean reused) Deprecated.static JspWriterstartBufferedBody(PageContext pageContext, BodyTag tag) Starts a buffered body for a tag that supports body content.static StringtoString(boolean b) Converts a boolean to its string representation.static StringtoString(byte b) Converts a byte to its string representation.static StringtoString(char c) Converts a char to its string representation.static StringtoString(double d) Converts a double to its string representation.static StringtoString(float f) Converts a float to its string representation.static StringtoString(int i) Converts an int to its string representation.static StringtoString(long l) Converts a long to its string representation.static StringtoString(short s) Converts a short to its string representation.static StringConverts an object to its string representation.static StringURL encodes a string, based on the supplied character encoding.
-
Field Details
-
GRAAL
public static final boolean GRAALIndicates whether the code is running under GraalVM native image.
-
-
Method Details
-
getThrowable
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
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
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
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
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
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
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
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
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
-
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 names- The string value to convertt- The target classpropertyEditorClass- The property editor class, ornull- Returns:
- the converted value
- Throws:
JasperException- if conversion fails
-
introspect
Sets bean properties from request parameters.- Parameters:
bean- The beanrequest- 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 beanprop- The property namevalue- The string valuerequest- The servlet requestparam- The parameter nameignoreMethodNF- Whether to ignore missing methods- Throws:
JasperException- if setting the property fails
-
toString
-
toString
Converts a byte to its string representation.- Parameters:
b- The byte value- Returns:
- the string representation
-
toString
Converts a boolean to its string representation.- Parameters:
b- The boolean value- Returns:
- the string representation
-
toString
Converts a short to its string representation.- Parameters:
s- The short value- Returns:
- the string representation
-
toString
Converts an int to its string representation.- Parameters:
i- The int value- Returns:
- the string representation
-
toString
Converts a float to its string representation.- Parameters:
f- The float value- Returns:
- the string representation
-
toString
Converts a long to its string representation.- Parameters:
l- The long value- Returns:
- the string representation
-
toString
Converts a double to its string representation.- Parameters:
d- The double value- Returns:
- the string representation
-
toString
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 namebean- The beanmethod- The methodvalues- Array valuest- The classpropertyEditorClass- The editor for the property- Throws:
JasperException- An error occurred
-
escapeQueryString
-
handleGetProperty
Gets the value of a bean property.- Parameters:
o- The beanprop- 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 beanprop- The property nameexpression- The EL expressionpageContext- The page contextfunctionMapper- The function mapper- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given int value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given short value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given long value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given double value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given float value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given char value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
Sets a bean property to the given byte value.- Parameters:
bean- The beanprop- The property namevalue- 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 beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
capitalize
-
getWriteMethod
Gets the write method (setter) for a bean property.- Parameters:
beanClass- The bean classprop- The property name- Returns:
- the write method
- Throws:
JasperException- if the property or write method cannot be found
-
getReadMethod
Gets the read method (getter) for a bean property.- Parameters:
beanClass- The bean classprop- 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 classattrName- The attribute nameattrValue- The attribute value as a stringpropertyEditorClass- 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 classattrName- The attribute nameattrValue- The attribute value as a string- Returns:
- the converted value
- Throws:
JasperException- if conversion fails
-
getContextRelativePath
Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.- Parameters:
request- The servlet request we are processingrelativePath- 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 processingresponse- The servlet response we are processingrelativePath- The relative path of the resource to be includedout- The Writer to whom we are currently writingflush- Should we flush before the include is processed?- Throws:
IOException- if thrown by the included servletServletException- if thrown by the included servlet
-
URLEncode
-
startBufferedBody
Starts a buffered body for a tag that supports body content.- Parameters:
pageContext- The page contexttag- The body tag- Returns:
- the JspWriter for the body content
- Throws:
JspException- if starting the buffered body fails
-
releaseTag
Deprecated. -
releaseTag
Releases a tag and destroys its instance.- Parameters:
tag- The tag to releaseinstanceManager- The instance manager
-
nonstandardSetTag
This method parallels the logic ofSetSupport.doEndTag().- Parameters:
pageContext- pageContextvar- name of the variablevalue- value to storescope- scope
-