1,
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib prefix =" S "uri ="/Struts-tags "%> <! -- You must add the struts2-dojo-plugin-corresponding version. jar to use Ajax --> <% @ taglib prefix = "SX" uri = "/Struts-Dojo-tags" %> <HTML> <! -- Must be added to the struts2-dojo-plugin-corresponding version. jar can use Ajax --> <s: Head theme = "XHTML"/> <SX: head parsecontent = "true" DEBUG = "true"/> <title> Huisheng Management System </title> <body> <a href = "action. JSP "> client API </a> <br> <Div id =" logindiv "> <Div id =" errordiv "> </div> <s: form name = "divloginform" id = "divloginform" Action = "login_admin" theme = "XHTML"> <s: label Label = "Enter your username and password"> </s: label> <s: textfield name = "Admin. name "label =" Account "value =" admin" /> <S: password name = "Admin. Password" label = "password" value = "admin"/> <! -- Sx executescripts --> <SX: Submit value = "login" formid = "divloginform" targets = "loginsuccessdiv" executescripts = "true"/> </s: form> </div> <Div id = "loginsuccessdiv" class = "Div" style = "display: none;"> </div> </body>
2 'after the action is submitted, assign the corresponding value session and request
public String login() { if(iAdminService.validate(admin.getName(), admin.getPassword())!=0){ getRequest().getSession(true).setAttribute("name", admin.getName()); getRequest().setAttribute("status", "success"); }else { getRequest().setAttribute("status", "failed"); } return "script"; }
3. scipt. jsp
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ taglib prefix =" S "uri ="/Struts-tags "%> <s: bean id = "date" name = "Java. util. date "/> <s: If test =" % {# request. status = 'success'} "> welcome, <s: property value =" # session. name "/>. logon Time: <s: Date name = "% {# date}"/> <s: URL action = "logout_admin" id = "divlogouturl"> </s: URL> <s: a href = "% {# divlogouturl}" theme = "XHTML"> deregister </s: A> <SCRIPT> // set error to an empty document. get Elementbyid ('errordiv '). innerhtml = ''; // hide the document in the logon box. getelementbyid ('logindiv '). style. display = 'none'; // display the successful information document. getelementbyid ('loginsuccessdiv '). style. display = ''; </SCRIPT> </S: If> <s: elseif test =" % {# request. status = 'failed'} "> <SCRIPT> document. getelementbyid ('errordiv '). innerhtml = "the password you entered does not match the account name. Please enter it again. "; </SCRIPT> </S: elseif> <s: else> <SCRIPT> // empty the successful information. Document. getelementbyid ('loginsuccessdiv '). innerhtml = ''; // The document is displayed in the login box. getelementbyid ('logindiv '). innerhtml = ''; // hide the successful information document. getelementbyid ('loginsuccessdiv '). style. display = 'none'; </SCRIPT> </S: else>
Done