JSP Data Type
There are four basic types:
Int data types include: byte (8 bits), short (16 bits), int (32 bits), long (64 bits ),
Float length data types include: single precision 32 bits float) and double precision 64 bits double)
Values of boolean type variables include true and false.
Char data types include: unicode characters, 16 characters
Corresponding class types: Integer, Float, Boolean, Character, Double, Short, Byte, Long
JSP data type conversion principles
Conversion from low-precision to high-precision
Byte, short, int, long, float, double, and char Note: When two char-type operations are performed, they are automatically converted to the int type. When char and other types are computed, it will be automatically converted to int type before automatic conversion of other types
Convert basic types to class types
Forward conversion: Use the class wrapper to generate a new class type variable.
- Integer a= new Integer(2);
Reverse conversion: using the class package
- int b=a.intValue();
Class type conversion to string
Forward conversion: because each class is a subclass of the object class, And all object classes have a toString () function, you can use the toString () function to convert it.
Reverse conversion: a new class type variable is generated through the class package.
- eg1: int i=Integer.valueOf(“123”).intValue()
JSP data type description: In the above example, a string is converted into an Integer object, and then the intValue () method of this object is called to return the corresponding int value.
- eg2: float f=Float.valueOf(“123”).floatValue()
JSP data type description: In the above example, a string is converted into a Float object, and then the corresponding float value is returned by calling the floatValue () method of this object.
- eg3: boolean b=Boolean.valueOf(“123”).booleanValue()
JSP data type description: In the preceding example, a string is converted into a Boolean object, and then the corresponding boolean value is returned by calling the booleanValue () method of this object.
- eg4:double d=Double.valueOf(“123”).doubleValue()
JSP data type description: In the preceding example, a string is converted into a Double object, and then the corresponding double value is returned by calling the doubleValue () method of this object.
- eg5: long l=Long.valueOf(“123”).longValue()
JSP data type description: In the preceding example, a string is converted into a Long object, and then the longValue () method of the object is called to return the corresponding long value.
- eg6: char=Character.valueOf(“123”).charValue()
JSP data type description: In the above example, a string is converted into a Character object, and then the charValue () method of this object is called to return the corresponding char value.
Conversion from basic type to string
Forward conversion of JSP data types:
For example:
- int a=12;
- String b;b=a+””;
Reverse conversion of JSP data types:
Package through class
- eg1:int i=Integer.parseInt(“123”)
JSP data type description: This method can only be used to convert strings into integer variables.
- eg2: float f=Float.valueOf(“123”).floatValue()
JSP data type description: In the above example, a string is converted into a Float object, and then the corresponding float value is returned by calling the floatValue () method of this object.
- eg3: boolean b=Boolean.valueOf(“123”).booleanValue()
JSP data type description: In the preceding example, a string is converted into a Boolean object, and then the corresponding boolean value is returned by calling the booleanValue () method of this object.
- eg4:double d=Double.valueOf(“123”).doubleValue()
JSP data type description: In the preceding example, a string is converted into a Double object, and then the corresponding double value is returned by calling the doubleValue () method of this object.
- eg5: long l=Long.valueOf(“123”).longValue()
JSP data type description: In the preceding example, a string is converted into a Long object, and then the longValue () method of the object is called to return the corresponding long value.
- eg6: char=Character.valueOf(“123”).charValue()
JSP data type description: In the above example, a string is converted into a Character object, and then the charValue () method of this object is called to return the corresponding char value.
- Two JSP Architectures
- Analyze JSP Background File Management source code
- Solution to Chinese garbled JSP found in MySQL Manual
- JSP Chinese garbled Problem description and Solution
- How to call JSP to read images from the database and display them on the page