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