Access to the Servelt API in the Action class

Source: Internet
Author: User

Package com.yu;


Import Com.opensymphony.xwork2.ActionContext;
Import Com.opensymphony.xwork2.ActionSupport;


public class Logincounteraction extends actionsupport{


/**
*
*/
Private static final long serialversionuid = 1L;
Private String UserName;
Private String UserPassword;
Public String GetUserName () {

return userName;
}
public void Setusername (String userName) {
This.username = UserName;
}
Public String Getuserpassword () {
return userpassword;
}
public void SetUserPassword (String userpassword) {
This.userpassword = UserPassword;
}
Public String counter () {
Gets the current Actioncontext object
Actioncontext Context=actioncontext.getcontext ();
/*string yu= "21312";
Context.getapplication (). put ("Yu", Yu); */
String appcounter= (String) context.getapplication (). Get ("Appcounter");
if (appcounter==null) {
appcounter= "1";
}else{
Appcounter=integer.tostring ((Integer.parseint (Appcounter) +1));
System.out.println (Appcounter);
}
Context.getapplication (). Put ("Appcounter", Appcounter);

if (username!=null) {
String sessioncounter= (String) context.getsession (). Get ("Sessioncounter");
if (sessioncounter==null) {
sessioncounter= "1";
}else{
Sessioncounter=integer.tostring ((Integer.parseint (Sessioncounter) +1));
System.out.println (Sessioncounter);
}
Context.getsession (). Put ("Sessioncounter", Sessioncounter);
Return "Success";
}else{

return "error";
}

}

}


<body>
<form action= "/chapter1/login.action" method= "POST" >

Account <input type= "text" name= "UserName" >
Password <input type= "password" name= "UserPassword" >
<input type= "Submit" value= "Login" >
</form>
</body>


<body>
                    Congratulations ${username}, you have successfully landed! <br>
          &NBSP
                    You are the first ${sessionscope.sessioncounter to visit this website! <br>,
                    This website has been visited ${applicationscope.appcounter Times <br>
  </body>

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE struts Public "-//apache software FOUNDATION//DTD struts Configuration 2.3
EN "HTTP://STRUTS.APACHE.ORG/DTDS/STRUTS-2.3.DTD" >
<struts>
<package name= "Logincode" extends= "Struts-default" >
<action name= "Login" class= "com.yu.LoginCounterAction" method= "Counter" >
<result name= "Success" >/Test1/loginSuccess.jsp</result>
<result name= "Error" >/Test1/loginFail.jsp</result>
</action>
</package>
</struts>


Access to the Servelt API in the Action class

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.