webwork test/ log

java 代码
 
  1. //============ the file name: D:\workspace\dweb\src\components.xml\components.xml  
  2. <?xml version="1.0" encoding="UTF-8"?>  
  3. <components>  
  4.   
  5.     <component>  
  6.   
  7.         <!--缁勪欢瀛樺湪鑼冨洿锛屽彲浠ユ槸request,session,application-->  
  8.   
  9.   
  10.         <scope>session</scope>  
  11.   
  12.   
  13.   
  14.         <class>Awebwork.ioc.larmRecord</class>  
  15.   
  16.   
  17.   
  18.         <enabler>webwork.ioc.AlarmRecordAware</enabler>  
  19.   
  20.     </component>  
  21.   
  22. </components>  
  23. //============ the file name: D:\workspace\dweb\src\messages_zh_CN.properties\messages_zh_CN.properties  
  24. xname=carlos  
  25. //============ the file name: D:\workspace\dweb\src\test.java\test.java  
  26.   
  27. public class test {  
  28.   
  29.       
  30.     public static void main(String[] args) {  
  31.         System.out.println("fffffffffff");  
  32.     }  
  33.       
  34. }  
  35.   
  36. //============ the file name: D:\workspace\dweb\src\validators.xml\validators.xml  
  37. <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 
  38. 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">  
  39.   
  40. <validators>  
  41.     <validator name="required"  
  42.         class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator" />  
  43.     <validator name="requiredstring"  
  44.         class="com.opensymphony.xwork.validator.validators.RequiredStringValidator" />  
  45.     <validator name="int"  
  46.         class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator" />  
  47.     <validator name="date"  
  48.         class="com.opensymphony.xwork.validator.validators.DateRangeFieldValidator" />  
  49.     <validator name="expression"  
  50.         class="com.opensymphony.xwork.validator.validators.ExpressionValidator" />  
  51.     <validator name="fieldexpression"  
  52.         class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator" />  
  53.     <validator name="email"  
  54.         class="com.opensymphony.xwork.validator.validators.EmailValidator" />  
  55.     <validator name="url"  
  56.         class="com.opensymphony.xwork.validator.validators.URLValidator" />  
  57.     <validator name="visitor"  
  58.         class="com.opensymphony.xwork.validator.validators.VisitorFieldValidator" />  
  59.     <validator name="conversion"  
  60.         class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator" />  
  61. </validators>  
  62.   
  63. //============ the file name: D:\workspace\dweb\src\webwork\action\HelloWebWorldAction-helloWebWorld-validation.xml\HelloWebWorldAction-helloWebWorld-validation.xml  
  64. <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 
  65. 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">  
  66. <validators>  
  67.     <field name="user.username">  
  68.         <field-validator type="requiredstring">  
  69.             <message>You must enter a value for username.</message>  
  70.         </field-validator>  
  71.     </field>  
  72.     <field name="user.password">  
  73.         <!--    WebWork 鏁欑▼ 鏈変换浣曟剰瑙佸拰寤鸿锛岃email to:achqian@hotmail.com锛圡SN锛? 鐗堟潈鎵?鏈夛紝璇峰嬁杞浇鍜岀鏀?-->  
  74.         <field-validator type="requiredstring">  
  75.             <message>You must enter a value for password.</message>  
  76.         </field-validator>  
  77.         <field-validator type="fieldexpression">  
  78.             <param name="expression">  
  79.                 user.password == verifyPassword  
  80.             </param>  
  81.             <message>Passwords don't match.</message>  
  82.         </field-validator>  
  83.     </field>  
  84.     <field name="user.email">  
  85.         <field-validator type="email">  
  86.             <message>You must enter a valid email.</message>  
  87.         </field-validator>  
  88.     </field>  
  89.     <field name="user.age">  
  90.         <field-validator type="int">  
  91.             <param name="min">6</param>  
  92.             <param name="max">100</param>  
  93.             <message>  
  94.                 Age must be between ${min} and ${max}, current value is  
  95.                 ${user.age}.  
  96.             </message>  
  97.         </field-validator>  
  98.     </field>  
  99. </validators>  
  100. //============ the file name: D:\workspace\dweb\src\webwork\action\HelloWebWorldAction.java\HelloWebWorldAction.java  
  101. package webwork.action;  
  102.   
  103.   
  104. import java.io.File;  
  105. import java.io.FileInputStream;  
  106.   
  107. import java.io.FileOutputStream;  
  108. import java.io.IOException;  
  109. import java.util.ArrayList;  
  110. import java.util.Date;  
  111. import java.util.List;  
  112. import java.util.Map;  
  113.   
  114. import javax.servlet.http.HttpServletRequest;  
  115.   
  116. import webwork.bean.User;  
  117. import webwork.ioc.AlarmRecord;  
  118. import webwork.ioc.AlarmRecordAware;  
  119.   
  120.   
  121. import com.opensymphony.webwork.ServletActionContext;  
  122. import com.opensymphony.webwork.dispatcher.ServletActionRedirectResult;  
  123. import com.opensymphony.webwork.interceptor.SessionAware;  
  124. import com.opensymphony.xwork.Action;  
  125. import com.opensymphony.xwork.ActionContext;  
  126. import com.opensymphony.xwork.ActionSupport;  
  127. import com.opensymphony.xwork.ModelDriven;  
  128.   
  129. public class HelloWebWorldAction implements Action, SessionAware,  
  130.         AlarmRecordAware {  
  131.     private int i;  
  132.   
  133.     private Map session;// 定义session变量  
  134.   
  135.     private AlarmRecord ar;  
  136.   
  137.     private File file;  
  138.   
  139.     public List getDays(){  
  140.         List list = new ArrayList();  
  141.         list.add("111111111111");  
  142.         list.add("22222222222");  
  143.         list.add("44444444444");  
  144.         return list;  
  145.     }  
  146.       
  147.     public HelloWebWorldAction() {  
  148.         System.out.println("the aciton has init.. ");  
  149.     }  
  150.   
  151.     /* 
  152.      * (non-Javadoc) 
  153.      *  
  154.      * @see webwork.ioc.AlarmRecordAware#setAlarmRecord(webwork.ioc.AlarmRecord) 
  155.      */  
  156.     public void setAlarmRecord(AlarmRecord alarm) {  
  157.         // TODO Auto-generated method stub  
  158.         this.ar = alarm;  
  159.     }  
  160.   
  161.     public void setSession(Map arg0) {  
  162.   
  163.         this.session = arg0;  
  164.   
  165.     }  
  166.   
  167.     private User user = new User();  
  168.   
  169.   
  170.     public User getUser() {  
  171.         return user;  
  172.     }  
  173.   
  174.     public void setUser(User user) {   
  175.         this.user = user;  
  176.     }  
  177.   
  178.     public String execute() throws IOException {  
  179.         // hello = "Hello, WebWorld!";  
  180.         System.out.println("the execute : " + i++);  
  181.         System.out.println("the upload file: " + file);  
  182.         // file upload test  .  
  183.         // 以下为保存文件,视情况修改  
  184.         if(null!=file)  
  185.         {  
  186.             FileOutputStream outputStream = new FileOutputStream("d://" + file.getName());  
  187.   
  188.             FileInputStream fileIn = new FileInputStream(file);  
  189.   
  190.             byte[] buffer = new byte[1024];  
  191.   
  192.             int len;  
  193.             while ((len = fileIn.read(buffer)) > 0)  
  194.             {  
  195.                 outputStream.write(buffer, 0, len);  
  196.             }  
  197.              
  198.             fileIn.close();  
  199.             outputStream.close();  
  200.              
  201.         }   
  202.           
  203.         ActionContext at = ActionContext.getContext();  
  204.         HttpServletRequest request = ServletActionContext.getRequest();  
  205.           
  206.           
  207. //      ar.setAlarmRecordID(this.toString());  
  208. //      System.out.println("--------" + ar.getAlarmRecordID());  
  209.         //session.put("user", user.toString());  
  210.         System.out.println( user );  
  211.   
  212. //      System.out.println("the action has access .. " + user  
  213. //              + new Date().toLocaleString());  
  214.         return SUCCESS;  
  215.     }  
  216.   
  217.     public String tttts() {  
  218.         // hello = "Hello, WebWorld!";  
  219.         System.out.println("the tttts : " + i++);  
  220.   
  221.         return SUCCESS;  
  222.     }  
  223.   
  224.     public String test() {  
  225.         // hello = "Hello, WebWorld!";  
  226.         System.out.println("the test : " + i++);  
  227.         ActionContext at = ActionContext.getContext();  
  228.   
  229.         at.getSession().put("user", user.toString());  
  230.   
  231.         System.out.println("the action has access .. " + user  
  232.                 + new Date().toLocaleString());  
  233.         return SUCCESS;  
  234.     }  
  235.   
  236.     @Override  
  237.     protected void finalize() throws Throwable {  
  238.         // TODO Auto-generated method stub  
  239.         super.finalize();  
  240.   
  241.         System.out.println(this + " the action has destoy...");  
  242.     }  
  243.   
  244.     /** 
  245.      * @return the file 
  246.      */  
  247.     public File getFile() {  
  248.         return file;  
  249.     }  
  250.   
  251.     /** 
  252.      * @param file the file to set 
  253.      */  
  254.     public void setFile(File file) {  
  255.         this.file = file;  
  256.     }  
  257.   
  258. }  
  259. //============ the file name: D:\workspace\dweb\src\webwork\action\Test.java\Test.java  
  260. package webwork.action;  
  261.   
  262. public class Test {  
  263.   
  264.     /** 
  265.      * @param args 
  266.      */  
  267.     public static void main(String[] args) {  
  268.         // TODO Auto-generated method stub  
  269.   
  270.     }  
  271.   
  272. }  
  273.   
  274. //============ the file name: D:\workspace\dweb\src\webwork\bean\User.java\User.java  
  275. package webwork.bean;  
  276.   
  277. public class User {  
  278.     private String username;  
  279.     private String password;  
  280.     private String email;  
  281.     private int age;  
  282.       
  283.     public User(){  
  284.         System.out.println("the user has init..");  
  285.           
  286.     }  
  287.       
  288.     public int getAge() {  
  289.         return age;  
  290.     }  
  291.     public void setAge(int age) {  
  292.         this.age = age;  
  293.     }  
  294.     public String getEmail() {  
  295.         return email;  
  296.     }  
  297.     public void setEmail(String email) {  
  298.         this.email = email;  
  299.     }  
  300.     public String getPassword() {  
  301.         return password;  
  302.     }  
  303.     public void setPassword(String password) {  
  304.         this.password = password;  
  305.     }  
  306.     public String getUsername() {  
  307.         return username;  
  308.     }  
  309.     public void setUsername(String username) {  
  310.         this.username = username;  
  311.     }  
  312.     public String toString(){  
  313.         return "username=" + username + ";password=" + password + ";email="  
  314.                 + email + ";age=" + age;  
  315.     }  
  316. }  
  317.   
  318. //============ the file name: D:\workspace\dweb\src\webwork\interceptor\MyInterceptor.java\MyInterceptor.java  
  319. package webwork.interceptor;  
  320.   
  321. import java.util.Calendar;  
  322.   
  323. import com.opensymphony.xwork.ActionInvocation;  
  324. import com.opensymphony.xwork.interceptor.AroundInterceptor;  
  325. import com.opensymphony.xwork.interceptor.Interceptor;  
  326.   
  327. public class MyInterceptor extends AroundInterceptor {  
  328.     public void init() {  
  329.           
  330.         System.out.println(" <<<<<<<the interceptor >>> " + Calendar.getInstance().getTime().toLocaleString());  
  331.     }  
  332.     public void destroy() { }  
  333.       
  334. //  public String intercept(ActionInvocation invocation) throws Exception {  
  335. //      System.out.println("???????????????????????????");  
  336. //      Calendar calendar = Calendar.getInstance();  
  337. //      System.out.println(" <<<<<<<the interceptor >>> "  
  338. //              + calendar.getTime().toLocaleString());  
  339. //      int hour = calendar.get(Calendar.HOUR_OF_DAY);  
  340. //      String greeting = (hour < 6) ? "Good evening"  
  341. //              : ((hour < 12) ? "Good morning"  
  342. //                      : ((hour < 18) ? "Good afternoon" : "Good evening"));  
  343. //  
  344. //      invocation.getInvocationContext().getSession()  
  345. //              .put("greeting", greeting);  
  346. //  
  347. //      String result = invocation.invoke();  
  348. //  
  349. //      return result;  
  350. //  }  
  351.     /* (non-Javadoc) 
  352.      * @see com.opensymphony.xwork.interceptor.AroundInterceptor#after(com.opensymphony.xwork.ActionInvocation, java.lang.String) 
  353.      */  
  354.     @Override  
  355.     protected void after(ActionInvocation arg0, String arg1) throws Exception {  
  356.         // TODO Auto-generated method stub  
  357.           
  358.         System.out.println("the after..*********************");  
  359.           
  360.     }  
  361.     /* (non-Javadoc) 
  362.      * @see com.opensymphony.xwork.interceptor.AroundInterceptor#before(com.opensymphony.xwork.ActionInvocation) 
  363.      */  
  364.     @Override  
  365.     protected void before(ActionInvocation arg0) throws Exception {  
  366.         // TODO Auto-generated method stub  
  367.         System.out.println("the before..");  
  368.           
  369.     }  
  370. }  
  371. //============ the file name: D:\workspace\dweb\src\webwork\ioc\AlarmRecord.java\AlarmRecord.java  
  372. package webwork.ioc;  
  373.   
  374. public class AlarmRecord {  
  375.   
  376.     private String AlarmRecordID;  
  377.   
  378.     public AlarmRecord() {  
  379.   
  380.         System.out.println("the alarmrecord creating..." + this);  
  381.     }  
  382.   
  383.     public void setAlarmRecordID(String id) {  
  384.         System.out.println("the setAlarmRecordID called  ");  
  385.         this.AlarmRecordID = id;  
  386.   
  387.     }  
  388.   
  389.     public String getAlarmRecordID() {  
  390.         System.out.println("the getAlarmRecordID called  ");  
  391.         return this.AlarmRecordID;  
  392.   
  393.     }  
  394.   
  395. }  
  396. //============ the file name: D:\workspace\dweb\src\webwork\ioc\AlarmRecordAware.java\AlarmRecordAware.java  
  397. package webwork.ioc;  
  398.   
  399. public interface AlarmRecordAware {  
  400.   
  401.     public void setAlarmRecord(AlarmRecord alarm) ;  
  402.   
  403. }  
  404. //============ the file name: D:\workspace\dweb\src\webwork\WebWorkTestCase.java\WebWorkTestCase.java  
  405. package webwork;  
  406.   
  407. import java.util.HashMap;  
  408. import java.util.Map;  
  409.   
  410. import webwork.action.HelloWebWorldAction;  
  411.   
  412. import com.opensymphony.xwork.Action;  
  413. import com.opensymphony.xwork.ActionContext;  
  414. import com.opensymphony.xwork.ActionProxy;  
  415. import com.opensymphony.xwork.ActionProxyFactory;  
  416.   
  417. import junit.framework.TestCase;  
  418.   
  419. public class WebWorkTestCase extends TestCase {  
  420.     public void testCreateUserWithProxyFactory() throws Exception {  
  421.         System.out.println(Action.SUCCESS);  
  422.         Map params = new HashMap();  
  423.         params.put("user.username","test");  
  424.         params.put("user.email""test@test.com");  
  425.         params.put("user.password""1234");  
  426.         params.put("user.confirm""1234");  
  427.         Map context = new HashMap();  
  428.         context.put(ActionContext.PARAMETERS, params);  
  429.         ActionProxyFactory factory = ActionProxyFactory.getFactory();  
  430.         ActionProxy proxy = factory.createActionProxy("""helloWebWorld",  
  431.                 context);  
  432.         // proxy.execute();  
  433.         HelloWebWorldAction action = (HelloWebWorldAction) proxy.getAction();  
  434.         String result = action.execute();  
  435.         assertEquals(result, Action.SUCCESS);  
  436.   
  437.     }  
  438. }  
  439.   
  440.   
  441.   
  442.   
  443.   
  444.   
  445.   
  446.   
  447.   
  448.   
  449. //============ the file name: D:\workspace\dweb\src\xwork.xml\xwork.xml  
  450. <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"   
  451. "http://www.opensymphony.com/xwork/xwork-1.0.dtd">  
  452.   
  453. <xwork>  
  454.     <!-- Include webwork defaults (from WebWork JAR). -->  
  455.     <include file="webwork-default.xml" />  
  456.     <include file="config-browser.xml" />  
  457.     <!-- Configuration for the default package. -->  
  458.     <package name="default" extends="webwork-default">  
  459.         <!-- Default interceptor stack. -->  
  460.         <interceptors>  
  461.             <interceptor name="greeting"  
  462.                 class="webwork.interceptor.MyInterceptor" />  
  463.    &nb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值