Web School Notes

Source: Internet
Author: User
Tags dateformat

You can record the items you have used in the past, so that you can take them away without saying hello.

/***************** (1) determine whether a session is available and then determine whether the user logs in, if you log in to obtain the encapsulated information in the session ****************/

If (request. isrequestedsessionidvalid ()){
Object User = session. getattribute ("user ");
If (user = NULL ){}
Else if (user! = NULL) Users user1 = (users) user;

}

// You can also judge the jump path based on whether the value in the session is null;

First, set the default link or jump path to the prompt for user login. However, if the value obtained in the session is not empty, the jump value is changed.

Example: <%
String userlink = "userloginplease. jsp ";
Userentity user = NULL;
If (session. getattribute ("user ")! = NULL ){
User = (userentity) Session. getattribute ("user ");
Userlink = "userupdate. jsp? Name = "+ User. getname ();
}
%>

/********************************** (2) the simple JS Code prompts the input validity ******************************** **********************/

<! --------- Jquery & Ajax check is name exise --------->

$ ("# Name"). BIND ("Blur", function () {// execue when input name lose it's focus
VaR AA = Document. getelementbyid ("name"). value;
// $ ('# Check'). slidetoggle (400). siblings ("DUV"). slideup ("slow"); // check is a div's ID
$ ('# Check'). Load ('checkname. jsp? Name = '+ AA + ');

});

<! ------------------- Click a span target and show a next Div --------------------------->

$ ("# Rightmessage span"). Click (function (){
$ (This). Next ("Div"). slidetoggle (300). siblings ("DUV"). slideup ("slow ");
})

<! * ---------------------------- Create a node to show erroe message !!!! ------------------------------------------------------------->

VaR A; var B;
VaR exise = false;
VaR par = Document. getelementbyid ("username ");
VaR par1 = Document. getelementbyid ("realname ");
Function showerror (a, B) {// a parameter is the error Display object, and one is the display text;
SPAN = Document. createelement ('span ');
Span. classname = 'error ';
Span. innerhtml = B;
A. parentnode. appendchild (SPAN );
}
Function removeerror (){
A. parentnode. removechild (SPAN );
}
Function checkform (){
$ ("# Username"). BIND ("Blur", function (){
If (par. value = ""){
If (! Exise ){
Showerror (PAR, "Please enter a name! ");
Exise = true;
Document. getelementbyid ("Submit"). Disabled = true;
} Else {
Removeerror (PAR );
}
});

<! ------------------------------ Determine the number and null value ------------------------------------->

VaR passcode = Document. getelementbyid ("passcode ");
VaR name = Document. getelementbyid ("name ");
Passcode. Regexp =/^ [0-9] + $ /;
Name. Regexp =/^. + /;
Document. getelementbyid ("frm"). onsubmit = function (){
If (! Passcode. Regexp. Test (passcode. Value )){
Alert ('enter a number for the password! ');
Return false;
}
If (! Name. Regexp. Test (name. Value )){
Alert ('user name cannot be blank! ');
Return false;
}
}

/**************************** Eval () and !!! **************************************** ******************/

Function getobj (objname) // call the eval () method to execute the text according to the JS Code and return the document model of this ID object based on the input ID.
{
If (document. getelementbyid ){
Return eval ('document. getelementbyid ("'+ objname + '")');
} Else {
Return eval ('document. all. '+ objname );
}
}

// Synchronizid change input value !!!!

Function changeinput (){
Getobj ("A2"). value = getobj ("A1"). value;
SetTimeout ("changeinput ()", 100)
}

Changeinput ();

/********************************* (2) sort by Unicode ************************************ **/

Public static void main (string [] ARGs) {// Test Method
String [] arr2 = {"3", "1", "2", "ACCC", "seeee", "BDD", "dddd", "cddd ", "GG", "ZZZZ", "wwww", "KKKK", "medium", "Count", "good", "Ah", "just "};
List list = sort (arr2 );
Showlist (list );
}
Public static list sort (string [] sortarr) {// you can sort 'abcd' or '123' of a character. It is a Unicode-encoded sequence and cannot contain Chinese characters.
Arraylist list = new arraylist ();
String temp;
For (INT I = 0; I <= sortarr. Length-1; I ++ ){
For (Int J = I + 1; j <= sortarr. Length-1; j ++ ){
// Compare the objects after I with I in sequence. If the result is greater than 0, after I, switch the position and select the sort method.
If (sortarr [I]. compareto (sortarr [J])> 0 ){
Temp = sortarr [I];
Sortarr [I] = sortarr [J];
Sortarr [J] = temp;
Count ++;
}
}
List. Add (sortarr [I]);
}
Return list;
}
Public static void showlist (list) {// display the result array;
For (INT I = 0; I <list. Size (); I ++ ){
System. Out. println ("Result:" + list. Get (I ));
}
System. Out. println ("number of moves:" + count );
}
/********************************* Java getcurrenttime () **************************************** *********************/

Public String currentlytime (){
Date = new date ();
Dateformat = dateformat. getdateinstance (dateformat. Full );
Return dateformat. Format (date );
}

/*************************************** * ** Java write log ********************************** **************/

Private Static void logout (string user, string MSG, string path ){
Filewriter out = NULL;
Try {
Out = new filewriter (path, true); // The parameter true table writes information to the file in append mode.
Out. Write (User + "on ");
Out. Write (gettime. gettime () + ":"); // Add the time before the written information
Out. Write (MSG + "\ r \ n ");
Out. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.