1. Chinese garbled characters in JSP web pages:
A problem occurs when user input is transmitted from one webpage to another through a request.
If the Chinese characters obtained by request. getparameter () cannot be correctly displayed, for example:
String username = request. getparameter ("username ");
If username is not correctly displayed, add the following sentence:
Username = new string (username. getbytes ("iso-8859-1"), "gb2312 ");
2. Get the current time
Public static string gettime (){
String format = "mm-dd-yyyy KK: mm a"; // format the date and time
Simpledateformat formatter = new simpledateformat (format );
Date nowdate = new date ();
Return formatter. Format (nowdate );
}
3. Format and display the time
Originaltime indicates the input time, And desttime indicates the time when the format is converted.
Public static string timeformat (string originaltime ){
Date = NULL;
String desttime = NULL;
// Set the time format first
Simpledateformat bartdateformat = new simpledateformat ("yyyy-mm-dd KK: mm ");
Try {
// Obtain the string time in this format and save it as a date object
Date = bartdateformat. parse (originaltime );
// To convert the string to the desired time type, format is also required.
Desttime = bartdateformat. Format (date );
}
Catch (exception ex ){
System. Out. println (ex. getmessage ());
}
Return desttime;
}
4. traverse all elements in the request
Java. util. Enumeration E = request. getparameternames ();
While (E. hasmoreelements ()){
String Param = (string) E. nextelement ();
// Perform subsequent operations on the element
}
5. automatically submit values using the hidden fields of the form
<Input type = "hidden" name = "ID" value = "XXXXX">
In this way, when a user submits a form, this value is filled in the relevant position of the request.