代码如下: /* * $header: d:/cvs/repository/struts-examples/web/040content/web-inf/src/java/examples/successaction.java,v 1.2 2003/06/13 06:23:13 sraeburn exp $ * $revision: 1.2 $ * $date: 2005/11/25 06:23:13 $ * this software consists of voluntary contributions made by many * individuals on behalf of the apache software foundation. for more * information on the apache software foundation, please see * . * by huhpreal */package action;import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts.action.action; import org.apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionmapping; /** * * @author huhpreal * @version $revision: 1.2 $ $date: 2003/06/13 06:23:13 $ */public class preusestrutsaction extends action { // ------------------------------------------------------------constructors /** * constructor for successaction. */ public preusestrutsaction() { super(); } // ---------------------------------------------------------- action methods /** * @param mapping the actionmapping used to select this instance * @param form the optional actionform bean for this request (if any) * @param request the http request we are processing * @param response the http response we are creating * * @exception exception if mapping.findforward throws an exception * * @return the "success" actionforward, or null if it cannot be found */ public actionforward execute( actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception { return mapping.findforward("success"); }}
processusestrutsaction.java:
代码如下:
/* * $header: d:/cvs/repository/struts-examples/web/040content/web-inf/src/java/examples/dyna/processdynaaction.java,v 1.3 2003/06/22 04:51:04 sraeburn exp $ * $revision: 1.3 $ * $date: 2005/11/25 04:51:04 $ * * this software consists of voluntary contributions made by many * individuals on behalf of the apache software foundation. for more * information on the apache software foundation, please see * */package action; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts.action.action; import org.apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionmapping; import org.apache.struts.action.dynaactionform; import bean.linkdb; /** * retrieve and process data from the submitted form * * @author huhpreal * @version $revision: 1.3 $ $date: 2005/11/25 04:51:04 $ */public class processusestrutsaction extends action { // ------------------------------------------------------------ constructors /** * constructor for processoptionsaction. */ public processusestrutsaction() { super(); } /** * @param mapping the actionmapping used to select this instance * @param form the optional actionform bean for this request (if any) * @param request the http request we are processing * @param response the http response we are creating * * @exception exception if the application logic throws an exception * * @return the actionforward for the next view */ public actionforward execute( actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception { system.out.println("enter into processusestrutsaction"); if (iscancelled(request)) { return mapping.findforward("home"); } /** * 获取表单信息 * 这里最好用bean实体封装 * 时间关系就不提取 */ string user=new string(""); string password=new string(""); string title=new string(""); string content=new string(""); string author=new string(""); user=(string) ((dynaactionform) form).get("user"); password=(string) ((dynaactionform) form).get("password"); title=(string) ((dynaactionform) form).get("title"); content=(string) ((dynaactionform) form).get("content");
author=(string) ((dynaactionform) form).get("author"); /*** * 数据库操作 */ linkdb linkdb=new linkdb(); string sqlstr="insert into conad (title,content,author) values('"+title+"','"+content+"','"+author+"')"; linkdb.executeupdate(sqlstr); // forward to result page return mapping.findforward("success"); }}