List serialization and deserialization to STRUTS2 <s:hidden> variables
Implementation method:
1, add the following Get/set method in the action class, you can not need the property:
2. Add the fields you want to serialize to the form
Hidden labels are used to Act ion transfer Parameters
The field to serialize for the JSP page corresponds to the Get/set method name of the action.
Serverspayexpendlist query out the recharge consumption new variable, is to serialize the original variable, the page through the Getserserverspayexpendlist () method to serialize the value of the serverspayexpendlist variable, The sequence is stored as a string in the serserverspayexpendlist of the page, and when the report is exported, the serserverspayexpendlist variable of the page is passed through the setserserverspayexpendlist () After the method is deserialized, it is stored in the serserverspayexpendlist variable again, so the information can be reused again, and the query and export report can be run faster.
The reason for storing serialized values with another variable is that STRUT2 does not support the existence of two variables of the same name on the same page, and serialization of a field string is also easy to transfer.
The methods for serializing and deserializing are as follows:
Appendix:
Import Java.io.bytearrayinputstream;import Java.io.bytearrayoutputstream;import Java.io.ioexception;import Java.io.objectinputstream;import Java.io.objectoutputstream;import Sun.misc.base64decoder;import sun.misc.base64encoder;/** * Serialization Tool class * @author file * @version 1.0 * @since 2013-04-11 */@SuppressWarnings ("restriction") p Ublic Final class Serializableutil {/** * base64 encryption */private static final Base64encoder Base64_encoder = new Base64Encode R ();/** * Base64 decryption */private static final Base64decoder Base64_decoder = new Base64decoder ();/** * Serialization * @param obj Object * @return string */public static <T> string serialize (T obj) {ObjectOutputStream oos = null; Bytearrayoutputstream BAOs = new Bytearrayoutputstream (); Serializes the try {oos = new ObjectOutputStream (BAOs); Oos.writeobject (obj); return Base64_encoder.encodebuffer ( Baos.tobytearray ());} catch (IOException e) {e.printstacktrace ();} Finally{try {if (oos!=null) oos.close (); if (baos!=null) Baos.close ();} catch (IOException e) {E.printstacktrace();} }return null;} /** * deserialization * @param str String * @param the object class returned by Clazz * @return Object */public static <T> T unserialize (String str,class< ; T> clazz) {Bytearrayinputstream Bais = null; ObjectInputStream ois = null; try {byte[] bytes = Base64_decoder.decodebuffer (str); Bais = new Bytearrayinputstream (bytes); ois = new ObjectInputStream (Bais); @SuppressWarnings ("Unchecked") T object = (T) ois.readobject (); return object;} catch (IOException e) {e.printstacktrace ();} catch (ClassNotFoundException e) {e.printstacktrace ();} finally{try {if (ois!=null) ois.close (); if (bais!=null) Bais.close ();} catch (IOException e) {e.printstacktrace ();} } return null;}}
List serialization and deserialization to STRUTS2 <s:hidden> variables