1. Global error prompt on the login page
<H: messages globalonly = "true"> Error_password: the password you entered is incorrect!
// Declare a message indicating no logon is successful
Facesmessage MSG = messagefactory. getmessage
(Facescontext, "error_password", ""); // The second is the message content, and the third is the setting parameter.
// In order to be consistent with the original example, the message severity level is set here
MSG. setseverity (facesmessage. severity_warn );
// Save the message in facescontext for other processes
Facescontext. addmessage (null, MSG );
// Return the result of the loginaction method,
// The result is a string used for comparison with the navigation rule,
// Navigate to the page after logon Failure
Return "failure ";
??? Method 2: Use exception classes
// Catch the usernotexistexception exception. For more information, see the preceding else annotations.
Facesmessage MSG = messagefactory. getmessage (facescontext,
UE. getmessage (), new object [] {UE. GetUserName ()});
MSG. setseverity (facesmessage. severity_warn );
Facescontext. addmessage (null, MSG );
// Record the user ID of the logon attempt in the log
Log. Warn (username + ": want log in! ");
Return "failure ";
Usernotexistexception ..
Private string username;
Public usernotexistexception (string newusername ){
// Super ("username" + newusername + "does not exist ");
/////////////////
Super ("error_usernotexist ");
This. Username = newusername;
}
Public String GetUserName (){
Return this. Username;
}
The username {0} corresponding to error_usernotexist cannot be found!
2.
Requirement Analysis
Analysts use the use case of the Unified Modeling Language (UML) to describe
Requirement.
Use Cases are generally represented by the use case diagram in combination with the document.
Use Case document writing.
The use case document generally contains the following content;
Use Case document, instructions on the page and business rules, and other
Requirements and other documents, and finally form the so-called rule specification.
3. MyFaces Upload Component
<H: Form ID = "form1" name = "form1" enctype = "multipart/form-Data">
<T: inputfileupload id = "fileupload"
Accept = "image /*"
Value = "# {newArticle. upfile }"
Storage = "file"
Styleclass = "fileuploadinput"
Required = "true"/>
NewArticle upfile Method
Facescontext =
Facescontext. getcurrentinstance ();
Httpservletrequest request = (httpservletrequest)
Facescontext. getexternalcontext (). getrequest ();
// Obtain the real directory of the application on the server, and then obtain the target directory for file upload.
String filepath = request. getsession (). getservletcontext ()
. Getrealpath ("/") + "image //";
// Get the file name of the uploaded source file
String srcfilename = uploadfile. getname ();
// Locate the position of "." Before the source file extension in the file name string
Int I = srcfilename. lastindexof (".");
// Get the extension of the source file
String extname = srcfilename. substring (I );
// Calculate the path and file name and extension of the uploaded target file
String targetfile = filepath + randomid + extname;
// Get the bytes of the uploaded file
Byte [] bytes = uploadfile. getbytes ();
// Call the File Upload method of the business service
Articleservice. uploadfile (targetfile, bytes );
The uploadfile method of articleservice. It is a binary stream.
? Restrict the file type and size.