Struts2 Action????????
???????????? ???????[ 2013/9/18 13:34:31 ] ????????
??????????
????TestAccountAction.java
package ut;
import action.AccountAction;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.config.ConfigurationProvider;
import org.apache.struts2.StrutsTestCase;
import static org.testng.AssertJUnit.*;
public class TestAccountAction extends StrutsTestCase {
private AccountAction action;
private ActionProxy proxy;
private void init() {
proxy = getActionProxy("/createaccount"); //action url??????д?????".action"???????д
action = (AccountAction) proxy.getAction();
}
public void testUserNameErrorMessage() throws Exception {
request.setParameter("accountBean.userName"?? "Bruc");
request.setParameter("accountBean.password"?? "test");
init();
proxy.execute();
assertTrue("Problem There were no errors present in fieldErrors but there should have been one error present"??
action.getFieldErrors().size() == 1);
assertTrue("Problem field account.userName not present in fieldErrors but it should have been"??
action.getFieldErrors().containsKey("accountBean.userName"));
}
public void testUserNameCorrect() throws Exception{
request.setParameter("accountBean.userName"?? "Bruce");
request.setParameter("accountBean.password"?? "test");
init();
String result=proxy.execute();
assertTrue("Problem There were errors present in fieldErrors but there should not have been any errors present"??
action.getFieldErrors().size()==0);
assertEquals("Result returned form executing the action was not success but it should have been."??
"success"?? result);
}
}
?????????????????action?е?validate??????????????????5????9???
????????struts.xml????????·????????£?????web-inf/classes?£??????????????????????????????
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd>
<struts>
<package name="testit" namespace="/" extends="struts-default">
<action name="createaccount" class="action.AccountAction">
<result name="success">/index.jsp</result>
<result name="input">/createaccount.jsp</result>
</action>
</package>
</struts>
????????action/result????????????jsp??棬?????????????????????У?????action???????????resultδ???????????????????????action??????μ????С????У????OK??
????????????????????μ????У??????????????????????????????????????????????????£?
????MyInterceptor.java
package interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class MyInterceptor extends AbstractInterceptor{
public String intercept(ActionInvocation actionInvocation) throws Exception {
System.out.println("before processing");
String rst= actionInvocation.invoke();
System.out.println("bye bye "+actionInvocation.getProxy().getMethod());
return rst;
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11